大佬教程收集整理的这篇文章主要介绍了在AngularJS中使用’scope’从另一个控制器调用控制器的方法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$scope.initRestId = function(){ var catapp = document.getElementById('SecondApp'); var catscope = angular.element(catapp).scope(); catscope.rest_id = $scope.user.username; catscope.getMainCategories(); };
我可以设置rest_id的值,但我不能调用getMainCategories由于某种原因。控制台显示此错误:@H_801_4@
编辑:@H_801_4@
angular.bootstrap(document.getElementById('firstAppID'),['firstApp']); angular.bootstrap(document.getElementById('secondAppID'),['secondApp']);
Scope Documentation@H_801_4@
在这里检出$ on,$ broadcast和$ emit。@H_801_4@
在一般用例中,angular.element(catapp).scope()的用法被设计为在角度控制器外部使用,如在jquery事件中。@H_801_4@
理想情况下,在您的使用,你会写一个事件在控制器1:@H_801_4@
$scope.$on("myEvent",function (event,args) { $scope.rest_id = args.username; $scope.getMainCategories(); });
在第二个控制器,你只是做@H_801_4@
$scope.initRestId = function(){ $scope.$broadcast("myEvent",{username: $scope.user.username }); };
你可以尝试包括firstApp模块作为第二个应用程序的依赖,你声明angular.module。这样你可以沟通到其他应用程序。@H_801_4@
以上是大佬教程为你收集整理的在AngularJS中使用’scope’从另一个控制器调用控制器的方法全部内容,希望文章能够帮你解决在AngularJS中使用’scope’从另一个控制器调用控制器的方法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。