event ( and js There's also bubbling and trapping )


<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.2/angular.js"></script> <div ng-controller="parent">parent:{{detail}}
<div ng-controller="test">
myself:{{detail}}
<div ng-controller="child">child:{{detail}}</div>
<button ng-click="addparent()">addparent</button>
<button ng-click="addchild()">addchild</button>
</div>
</div>
<script>
var app = angular.module('app', [])
.controller('parent', ['$scope',function($scope) {
$scope.detail =1;
$scope.$on('add',function(){
$scope.detail +=1;
}); }]).controller('child', ['$scope',function($scope) {
$scope.detail =1;
$scope.$on('add',function(){
$scope.detail +=1;
}); }]).controller('test', ['$scope',function($scope) {
$scope.detail =1;
$scope.$on('add',function(){
$scope.detail +=1;
});
$scope.addparent=function(){
$scope.$emit('add');
};
$scope.addchild=function(){
$scope.$broadcast('add');
};
}]);
angular.bootstrap(document, ['app']);
</script>
</html>

As you can see from the code above $on To subscribe to an event ,$emit The event triggered will bubble to handle ,
$broadcast Triggered events capture ,
The system also has many built-in events to subscribe to , For example, whether routing is successful or not $routeChangeError and $routeChangeSuccess

ng-bind-html-unsafe( Removed from the new version , You can create a new instruction dependency ngSanitize)


<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.2/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.2/angular-sanitize.js"></script>
<div ng-controller="parent" ng-bind-html-unsafe="html"></div>
<script>
angular.module('app', ['ngSanitize']).config(['$compileProvider',
function($compileProvider) {
$compileProvider.directive({
ngBindHtmlUnsafe: function() {
return function(scope, element, attr) {
element.addClass('ng-binding').data('$binding', attr.ngBindHtmlUnsafe);
scope.$watch(attr.ngBindHtmlUnsafe,
function ngBindHtmlUnsafeWatchAction(value) {
element.html(value || '');
});
}
}
});
}]).controller('parent', ['$scope',
function($scope) {
$scope.html = "<span>aaa</span>";
}]);
angular.bootstrap(document, ['app']);
</script>
</html>

After understanding the usage of the instruction , I think it's very simple


Ⅶ.AngularJS Every bit of -- More articles about the event

  1. Ⅵ.AngularJS Every bit of -- Instructions

    Instructions Basic usage <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.2/angul ...

  2. Ⅴ.AngularJS Every bit of -- Resources and filtering

    resources ngResource( rely on ngResource modular ) <html> <script src="http://ajax.googleapis.com/ajax/libs/ ...

  3. AngularJS HTML DOM&amp; event

    AngularJS by HTML DOM The attributes of the element provide instructions for binding application data . ng-disabled  Instruction to bind application data directly to HTML Of disabled attribute <div ng-app= ...

  4. AngularJS Learning events

    1.ng-click Instructions : Defined AngularJS Click event <div ng-app="" ng-controller="myCtrl"> <b ...

  5. angularJS Supported events

    AngularJS Provide information that can be used with HTML Control is associated with multiple events . for example ng-click Usually associated with buttons . Here are AngularJS Supported events . ng-click ng-dbl-click ng-mousedown ...

  6. angularjs Of touch event

    angularJs No, touch event . Here is a touch Instructions . ngTouch.js "use strict"; angular.module("ngTouch&qu ...

  7. Ⅳ.AngularJS Every bit of -- service

    service (Angularjs A lot of methods are made up of services ) 1. Use service Method to create a singleton service <html> <script src="http://ajax.googleap ...

  8. Ⅲ.AngularJS Every bit of -- route

    route ngRoute ( Need to rely on ngRoute modular ) <html> <script src="http://ajax.googleapis.com/ajax/libs/ang ...

  9. Ⅱ.AngularJS Every bit of -- cache

    Template cache -$templateCache and Cache factory $cacheFactory 1. Use script label <html ng-app> <script src="htt ...

Random recommendation

  1. [ Release ]SuperIO v2.2.5 Integrate OPC The service side and OPC client

    SuperIO download : Download from this website Baidu SkyDrive 1. Repair serial port number greater than or equal to 10 When it comes to IO Unknown status . 2. Optimize RunIODevice(io) Function internal processing flow , Secondary development can overload this interface . 3. Optimize IO receive data , ...

  2. ( turn )AppiumLibrary Basic operation

    *** Settings *** Library AppiumLibrary Library Collections Library String Library Dialogs *** Test C ...

  3. java 14 -5 System class

    System Class contains some useful class fields and methods . It cannot be instantiated . Method : 1.public static void gc(): Run the garbage collector . 2.public static void exit(int s ...

  4. Method Overloading in WCF zt

    Method overloading is the process of implementing Polymorphism in Object-Oriented Programming. A met ...

  5. uva10934 Dropping water balloons

    // It's been a long time I've been out of shape Then I brush a water topic to play // Winter training and school competition have achieved similar topics But it wasn't ( In fact, not now The question : Yes k Two balloons and one n A tall building , The balloon has hardness , It happened to break in some place , Ask at least how many experiments ...

  6. Dom Operate advanced applications

    table tBodies,tHead,tFoot,rows,cells One table There are many. tbody oTab.tBodies[0].rows[i].style.background = &quo ...

  7. 2015 ICL, Finals, Div. 1 Ceizenpok’s formula( Modular of combinatorial data , Expand lucas Theorem )

    J. Ceizenpok’s formula time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  8. be based on Java Of ArrayList and LinkedList The realization and summary of

    One . Definition MyList Interface , Common ways to include lists : import java.util.Iterator; /** * The linear table ( list ) Interface definition of */ public interface MyList<T ...

  9. Office supplies management system VB—— Stock quantity export EXCEL,SaveEXCEL

    Office supplies management system VB—— Stock quantity export EXCEL,SaveEXCEL On the whole ,VB Of EXCEL The export efficiency is still quite low , Is a small office supplies management software , No more optimization . Pressed for time , It doesn't work from beginning to end C# To write , ...

  10. Python - Something worth reading PEP

    1- PEP brief introduction PEP yes Python Enhanced proposal (Python Enhancement Proposal) Abbreviation . The community passes through PEP Here it is Python Words make suggestions , New features and changes in each version are made through PEP Proposal process ...