我有两个控制器。在一个控制器中,我将数据存储在不同类别和不同周和天的范围变量中。这是相同的功能:
$scope.fetchWeekList = function(type) {
$scope.loading = true;
var paramtype = (type == 'mo')?'Mobiles':((type == 'ta')?'Tablets':((type == 'la')?'Laptops':'TVs'));
var weekListUrl = url + "/" + paramtype;
var request = $http({
method: "GET",
url: weekListUrl,
headers: { 'Accept' :'application/json','Content-Type' :'application/json', 'Accept-Language': 'en'}
});
request.success(
function(data) {
$scope.weekList = data.object;
$scope.loading = false;
});
request.error(
function(data, status) {
console.log(status);
$scope.weekList = data || "Request failed";
$scope.loading = false;
});
};
请注意,我正在使用这个单一功能获取所有类别的周列表数据。
然后我正在使用这个:
$scope.$on('fetchSaleDetails', function(event,type) {
$scope.fetchWeekList(type);
}
然后我像这样在另一个控制器中广播它:
$rootScope.$broadcast('fecthSaleDetails','mo');
$rootScope.$broadcast('fecthSaleDetails','ta');
$rootScope.$broadcast('fecthSaleDetails','la');
但是当我切换公司时,一个类别的周数会出现在另一个类别中,当我再次单击该公司时,数据会发生变化。这是更新公司的功能。
$scope.updateCom = function(corresCom) {
$("html, body").animate({scrollTop: 0 }, "slow");
$rootScope.$broadcast('updateComDetail',corresCom);
$rootScope.$emit('fetchSaleDetails','mo');
$rootScope.$broadcast('fecthSaleDetails','mo');
$rootScope.$broadcast('fecthSaleDetails','ta');
$rootScope.$broadcast('fecthSaleDetails','la');
$scope.selectedCom = corresCom;
};
如果有人能在这里告诉我这个问题,我将不胜感激。我已经尽力了,但没有运气。
谢谢。