控制器之间通信的正确方法是什么?
我目前正在使用一种可怕的软糖包括window:
function StockSubgroupCtrl($scope, $http) {
$scope.subgroups = [];
$scope.handleSubgroupsLoaded = function(data, status) {
$scope.subgroups = data;
}
$scope.fetch = function(prod_grp) {
$http.get('/api/stock/groups/' + prod_grp + '/subgroups/').success($scope.handleSubgroupsLoaded);
}
window.fetchStockSubgroups = $scope.fetch;
}
function StockGroupCtrl($scope, $http) {
...
$scope.select = function(prod_grp) {
$scope.selectedGroup = prod_grp;
window.fetchStockSubgroups(prod_grp);
}
}
Run Code Online (Sandbox Code Playgroud) 试图找到AngularJS的一些基本信息$rootScope.$broadcast,但AngularJS文档没有多大帮助.简单来说,我们为什么要使用它?
此外,在John Papa的Hot Towel模板中,公共模块中有一个名为的自定义函数$broadcast:
function $broadcast() {
return $rootScope.$broadcast.apply($rootScope, arguments);
}
Run Code Online (Sandbox Code Playgroud)
我不明白这是做什么的.所以这里有几个基本问题:
1)做$rootScope.$broadcast什么?
2)$rootScope.$broadcast和之间有什么区别$rootScope.$broadcast.apply?