問題:
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?