Handling data binding in AngularJS Services

前端 未结 3 578
遥遥无期
遥遥无期 2020-12-25 13:47

I\'m trying to figure out how you handle binding properly when my data is stored in a service.

I can get things working if it put the service into the $scope and the

3条回答
  •  有刺的猬
    2020-12-25 14:40

    You can bind to services using $watch and passing a function:

    $scope.$watch( function () { return myService.drawing; }, function ( drawing ) {
      // handle it here. e.g.:
      $scope.drawing = drawing;
    });
    

    And then use $scope.drawing in your templates and they will automatically update:

    {{ drawing }}

提交回复
热议问题