javascript - How can I access the another ng-controller ng-model from another ng-controller? -


i want access ng-model ng-controller possible , how?. in following code using 2 controller, first controller having mddl1 , 1 controller don't have other model. want access model value 2nd controller method.

<div ng-controller="cnt_fnt"> <select id="dflfnt" ng-model='mddl1' ng-options='option.name option in ddl1options.data'>  </select> </div> <div ng-controller="ctrl_opsection" ng-model="opmodel"> </div> <script> ---- .controller('cnt_fnt', ['$scope', function ($scope) { $scope.ddl1options={ data:[ {value:"georgia, serif",name:"style 1"}, {value:"'times new roman', times, serif",name:"style 3"}, {value:"arial, helvetica, sans-serif",name:"style 4"} ]};   alert($scope.mddl1.value); //here can access dropdown value }]) .controller("ctrl_opsection",["$scope",function($scope){     alert(cnt_fnt.mddl1.value); //i want access here dropdown value  }]); </script> 

i tried access ng-model value ng-controller value following code.

alert(cnt_fnt.mddl1.value); //controller_name.modelname 

in common, use service . when parentctrl send data childctrl, can use $broadcast $on.conversely, can use $emit $on.

 `controller('cnt_fnt', ['$scope','inter', function($scope,inter){     inter.data = $scope.mddl1.value;   }])   .controller('dockctr', ['$scope', 'inter', function($scope, inter){      alert(inter.data)   }]);    app.service('inter', function(){    return {     }   });` 

Comments