scope - Angularjs synchronize the value in different part but under same module same controller -


How to synchronize $ scope.department in 2 controllers No matter, I enter the value in which input, $ scope The .department can still update the base on the input field. Angulus ver app = angular Module ('app', []); App.controller ('GreetCtrl', function ($ scope) {$ scope.department = "human resources department";}); HTML & lt; Body ng-app = "app" & gt; & Lt; Div class = "show-scope-demo" & gt; & Lt; Div ng-controller = "GreetCtrl" & gt; & Lt; Input type = "text" ng-model = "section" & gt; {{Department}} & lt; / Div & gt; & Lt; Div ng-controller = "GreetCtrl" & gt; & Lt; Input type = "text" ng-model = "section" & gt; {{Department}} & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Body & gt;

You can make this happen in angular JS

then department will always include the "Human Resources Department".

  var app = angular.module ('app', []); App.constant ("department", "human resources department"); App.controller ('GreetCtrl', function ($ scope, department) {$ scope.department = department;});   

But you should do something like that which is going to erase you.

HTML

  & lt; Div class = "show-scope-demo" & gt; & Lt; Div ng-controller = "GreetCtrl" & gt; & Lt; Input type = "text" ng-model = "section" ng-change = "stop ()" & gt; {{Department}} & lt; / Div & gt; & Lt; Div ng-controller = "GreetCtrl" & gt; & Lt; Input type = "text" ng-model = "section" ng-change = "stop ()" & gt; {{Department}} & lt; / Div & gt; & Lt; / Div & gt;   

script

  var app = angular Module ('app', []); App.constant ("department", "human resources department"); App.controller ('GreetCtrl', function ($ scope, department) {$ scope.department = section; $ scope.preventChange = function () {$ scope.department = section;}});    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -