AngularJS : How to watch service variables?

后端 未结 21 1652
盖世英雄少女心
盖世英雄少女心 2020-11-22 09:12

I have a service, say:

factory(\'aService\', [\'$rootScope\', \'$resource\', function ($rootScope, $resource) {
  var service = {
    foo: []
  };

  return          


        
21条回答
  •  执笔经年
    2020-11-22 09:22

    Have a look at this plunker:: this is the simplest example i could think of

    http://jsfiddle.net/HEdJF/


    Input is : {{Data.FirstName}}

    Input should also be here: {{Data.FirstName}}
    // declare the app with no dependencies var myApp = angular.module('myApp', []); myApp.factory('Data', function(){ return { FirstName: '' }; }); myApp.controller('FirstCtrl', function( $scope, Data ){ $scope.Data = Data; }); myApp.controller('SecondCtrl', function( $scope, Data ){ $scope.Data = Data; });

提交回复
热议问题