试图使用$ scope。$ apply(),但它会抛出错误“$ scope。$ apply is a function”

时间:2015-10-08 16:41:07

标签: angularjs apply angularjs-service

尝试调用$scope.$apply,但抛出错误说:

  

$ scope。$ apply不是函数

以下是代码:

function loadUnitChanged(event, data) {
        console.log('Event Info: ', event);
            setTimeout(function () {
                $scope.$apply(function () {
                    $scope.cargoregisters = createArrayFromLoadUnit(data);
                });
            }, 2000);           
    }

=============================================== ==========

 angular.module('portwin.cargo').controller('CargoController', function     ($rootScope, $location, $timeout, $mdDialog, cargoGateway) {
    var $scope = this;

    // Event handlers
    $rootScope.$on('cargodetails:loaded', cargoDetailBaseDataLoaded);
   $rootScope.$on('cargoRegistration:loaded',      cargoRegistrationBaseDataLoaded);
    $rootScope.$on('loadUnit:changed', loadUnitChanged);
    $rootScope.$on('loadUnit:Saved', updateLoadUnitAfterSave);

1 个答案:

答案 0 :(得分:0)

编辑: 由于您可以根据您的评论访问$ scope,我会这样做......

...
public static class SubClassView extends LinearLayout {
...