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);
        });
      })
相關文章
相關標籤/搜索