Angularjs inside $emit, $broadcast, $on, $http. Jsonp,constant is the use of notes

Source: Internet
Author: User
Tags emit

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.