Angularjs service callback to update scope of controller

后端 未结 4 760
[愿得一人]
[愿得一人] 2021-01-31 18:49

A service with a 3rd party library callback function:

mbAppModule.service(\'aService\', function ($http) {
    this.data={\"somedata\":0};
    var m3rdPartLib=\         


        
4条回答
  •  情话喂你
    2021-01-31 19:23

    I needed to update an input field from a service because it had listeners and what not that changed data randomly and dynamically.

    This could be used to call scope functions in the controller as well:

    //scope will be set to current scope of a controller
    //which has an ng-view containing this element    
    var scope = angular.element('#input-element').scope();
    //wrap changes in an apply call to make sure view and model are consistent
    scope.$apply(function() {
        scope.object.data = value;
    });
    

    Thanks to this post: How do I access the $scope variable in browser's console using AngularJS?

提交回复
热议问题