Angular: share asynchronous service data between controllers

前端 未结 1 1940
刺人心
刺人心 2020-12-18 16:03

I would like to \"bind the change\" of asynchronous data between controllers.

I know it\'s a probably a bit confusing but I hope something is possible.

In th

相关标签:
1条回答
  • 2020-12-18 16:54

    you are returning a promise in the factory's return object and not the actual object itself. so in you scope you should actually wait for the promise to mend a concrete object then assign it to $scope.message

    example:

    function ControllerA($scope, myService) {
         myService.getMessage().then(function(obj){
                  $scope.message=obj
                 });
    }
    

    i changed your fiddle into something that might be your answer, see this fiddle

    0 讨论(0)
提交回复
热议问题