Update scope value when service data is changed

后端 未结 6 1241
天命终不由人
天命终不由人 2020-11-27 10:57

I have the following service in my app:

uaInProgressApp.factory(\'uaProgressService\', 
    function(uaApiInterface, $timeout, $rootScope){
        var facto         


        
6条回答
  •  [愿得一人]
    2020-11-27 11:45

    No $watch or etc. is required. You can simply define the following

    uaInProgressApp.controller('ua.InProgressController',
      function ($scope, $rootScope, $routeParams, uaContext, uaProgressService) {
        uaContext.getSession().then(function(){
            uaContext.appName.set('Testing house');
            uaContext.subAppName.set('In progress');
            uaProgressService.startCron();
        });
    
        $scope.getTaskList = function() {
          return uaProgressService.taskList;
        };
      });
    

    Because the function getTaskList belongs to $scope its return value will be evaluated (and updated) on every change of uaProgressService.taskList

提交回复
热议问题