控制器之间的角度传递数据 [英] Angular pass data between controller
本文介绍了控制器之间的角度传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个需要在控制器之间共享数据的要求,所以我创建了工厂
I have requirement where i need to share data between controllers,so i created factory
假设我的网址是:abc/123(注意:123是动态的,我需要从控制器传递它)
suppose i have url like: abc/123 (Note:123 is dynamic i need to pass it from controller)
MyCode
appServices.factory('classesService', function($http){
return {
getClasses: function(value) {
return $http.get(urlprefix + 'orgs/' + value + '/classes?with-users=true');
}
};
});
在控制器中
classesService.getClasses($scope.organization.id).then(function(data){});
现在假设我正在3个控制器中使用它,那么3个呼叫将转到服务器.我不想打三个电话,我只想打一个电话.
now suppose i am using it in 3 contollers 3 calls will go to server. i dont want three calls i want only one call.
注意:这三个控制器的值都相同
Note:value is same for all three controller
有什么办法可以做到这一点.
is there any way i can acheive this.
谢谢
推荐答案
You can use UI-ROUTER-EXTRAS "https://christopherthielen.github.io/ui-router-extras/#/home"
这篇关于控制器之间的角度传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文