angularJs 广播与接收

angularJs 广播与接收

  1. 父$scope 广播 子$scopespa

    // 父做用域
    HIS.controller('父做用域',function($scope){
      // 发起广播
      $scope.$broadcast('广播名',msg)
    })
    
    
    ​​// 子做用域
    HIS.controller('子做用域',function($scope){
      // 接收
      $scope.$on('广播名', function(event,msg) {
           console.log(msg);
      });
    })
    

     

    1. 子$scope 广播 父$scope 作用域

      // 父做用域
      HIS.controller('父做用域',function($scope){
        // 发起广播
        $scope.$emit('广播名',msg)
      })
      
      
      ​// 子做用域
      HIS.controller('子做用域',function($scope){
        // 接收
        $scope.$on('广播名', function(event,msg) {
             console.log(msg);
        });
      })
相关文章
相关标签/搜索