AngularJS: Using Shared Service(with $resource) to share data between controllers, but how to define callback functions?

前端 未结 4 748
自闭症患者
自闭症患者 2020-12-11 04:45

Note: I also posted this question on the AngularJS mailing list here: https://groups.google.com/forum/#!topic/angular/UC8_pZsdn2U

Hi All,

I\'m building my fi

4条回答
  •  臣服心动
    2020-12-11 04:57

    In this new scenario you could use a $scope.$watch. The way you use it is as follows.

    $scope.countries = CountryService.getCountries();
    
    $scope.$watch('countries',function(newValue){
    //need to check if newValue has a value because 
    //the first time watch fires it will be undefined.
        if(newValue && newValue.length > 0 ){
            $scope.selected.country = $scope.countries[0];
        }
    });
    

    Hope this helps.

提交回复
热议问题