Just looked at some of the online communication between the controllers, and then combined with their own projects to do some, here is the main thing to do is the controller communication between the two peers.
Html:
1 <HTML>2 <Scriptsrc= "Http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js"></Script>3 <Body>4 <DivNg-app= "App">5 <DivNg-controller= "CHILDCTR1">Name:6 <inputNg-model= "Name"type= "text" />7 </Div>8 <DivNg-controller= "CHILDCTR2">Ctr1 Name:9 {{Ctr1name}}Ten </Div> One </Div> A </Body> - </HTML>
The above HTML code set the 2 siblings of the controller, now CHILDCTR2 need CHILDCTR1 parameters to display the relevant information, the following is the controller CHILDCTR1 code:
1 angular.module ("app", [])2function ($scope) {3 $scope. $watch ("name",function () {// listen to the binding "name" and send a message when a change occurs;4 // alert ("123"); 5 $scope. $emit ("Ctr1namechange", $scope. Name); // send a message named Ctr1namechange with a value of $scope.name 6 }); 7 });
Here is the code for CHILDCTR2:
Angular.module ("App", []). Controller (function ($scope) { $scope. $on (" Ctr1namechange ",//monitor There is no message named" Ctr1namechange ", if any, execute the following function functions (event, msg) { Console.log ("childCtr2", msg); = msg; } );
The above is a separate file for the controller to write the different forms; Of course, you can merge them into one page
1Angular.module ("App", [])2. Controller ("CHILDCTR1",function($scope) {3$scope. $watch ("name",function (){4 //alert ("123");5$scope. $emit ("Ctr1namechange", $scope. Name);6 });7}). controller ("CHILDCTR2",function($scope) {8$scope. $on ("Ctr1namechange",9 Ten function(event, msg) { OneConsole.log ("ChildCtr2", msg); A$scope. Ctr1name =msg; - }); -});
There are many communication methods between the controller, including the server's factory, can refer to: http://jsbin.com/hopazo/5/edit?html,css,js,output
Communication between the ANGULARJS controller