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. You can make this happen in then But you should do something like that which is going to erase you. HTML script 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;
angular JS
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;});
& 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;
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
Post a Comment