This film mainly introduces $emit, $broadcast, $on often developed usage!
This figure is pretty much the $emit, $broadcast the mechanics and the useful in AJ!
This article describes the principles and places of attention of AJ inside using JSONP! Below is a direct display of the interface I run up! Then paste the DOM and JS code, this article does not say much, share some common things! Dom+js Code:
<! DOCTYPE html>"en">"UTF-8"> <title>Broadcasting</title> <script src="./bower_components/angular/angular.min.js"></script> <script type="Text/javascript">varApp = Angular.module ('app',[]); App.controller ('Firstctrl', Function ($scope) {$scope. $on ('EventName', Function (Event, args) {$scope. Message=Args.message; Console.log ($scope. Message); }); }); App.controller ('Secondctrl', Function ($scope) {$scope. Handleclick=function (msg) {$scope. $emit ('EventName', {message:msg}); }; }); App.controller ('Threectrl', Function ($scope) {$scope. HandleClick1=function (msg) {$scope. $broadcast ('EventName', {message1:msg}); }; }); App.controller ('Fourctrl', Function ($scope) {$scope. $on ('EventName', Function (Event, args) {$scope. message1=Args.message1; Console.log ($scope. message1); }); }); App.controller ('Myjsonpctrl',['$scope','$http', function ($scope, $http) {$scope. Clickjsonp=function () {$http. JSONP ('Http://angularjs.org/greet.php?callback=JSON_CALLBACK',{params: {Name:' World'},cache:true}). Success (function (data) {$scope. Jsonps=data.greeting; }); } }]); App.constant ('Myconfig', {config1:' -', Config2:'Actionbyname', }); App.controller ('Constctrl', function ($scope, myconfig) {$scope. Const1=MYCONFIG.CONFIG1; $scope. Const2=Myconfig.config2; }); </script>"app"><div ng-controller="Firstctrl"style="border:2px solid #E75D5C; padding:5px;"> "Secondctrl"style="border:2px solid #428bca;p adding:5px;"> "msg"> <button ng-click="Handleclick (msg);">Emit</button> </div></div><div ng-controller="Threectrl"style="border:2px solid #E75D5C; padding:5px;"> "msg"> <button ng-click="handleClick1 (msg);">Broadcast</button> <br/><br/> <div ng-controller="Fourctrl"style="border:2px solid #428bca;p adding:5px;"> "Myjsonpctrl"style="border:2px solid #E78F5D; padding:5px;"> <input ng-model="Jsonps"> <button ng-click="Clickjsonp ()"> Try Jsonp value </button></div><div style="border:2px solid #E10F5B; padding:5px;"Ng-controller="Constctrl"> <input ng-model="Const1"><br> <input ng-model="Const2"></div></body>Angularjs inside $emit, $broadcast, $on, $http. Jsonp,constant is the use of notes