angular1.x事件处理

angular1.x事件处理方式

  • on()注册一个事件,

  • emit() 调用父级事件,向上传播。

  • broadcast()向下传播事件。

name :
Ctr1 name:
angular.module("app", [])
    .controller("parentCtr", function ($scope) {        
              $scope.$on('parentChange',function (event, msg) { 
                       $scope.$broadcast('ChildCtr1NameChange',msg);        
                      })
             })
      .controller("childCtr1", function ($scope) {
               $scope.change = function (name) {
                     console.log("childCtr1", name); 
                $scope.$emit("parentChange", name);
               };    
          })
       .controller("childCtr2", function ($scope) { 
            $scope.$on('ChildCtr1NameChange',function (event, msg) {
                   $scope.ctr1Name = msg;        })
        });

你可能感兴趣的:(angular1.x事件处理)