AngularJS中控制器之间通信的正确方法是什么? - What's the correct way to communicate between controllers in AngularJS?

问题:

What's the correct way to communicate between controllers? 控制器之间通信的正确方法是什么?

I'm currently using a horrible fudge involving window : 我目前正在使用涉及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);
    }
}

解决方案:

参考一: https://stackoom.com/question/lDMS
参考二: What's the correct way to communicate between controllers in AngularJS?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章