【发布时间】:2017-07-13 13:27:01
【问题描述】:
我需要一个函数,我可以使用 $window.history.back() 从每个视图中调用,而不管哪个控制器控制该页面。
.run(['$rootScope', '$state', 'CommonUserModel', 'InitialiseService','$window', function($rootScope, $state, $window, commonUserModel, initialiseService) {
$rootScope.link = function(){
$window.history.back();
};
所以我把这个函数放在了应用模块中。注入窗口对象,因为它抱怨它。但现在它也抱怨它“无法读取未定义的属性'back'”。
当我阅读 StackOverflow 时,我正在使用来自其他控制器的 $rootScope 调用此函数。我不得不像这样将 $rootScope 注入其他控制器。
homeViewModule.controller("simDetailsController", [ '$rootScope','$scope', 'ModalDialogService', 'CommonTagModel', '$location','$window',
function($scope, modalDialogService, commonTagModel, $location, $window,$rootScope) {
self.link = function(){
$rootScope.link();};
你能给我一个建议吗? 请记住,我是 AngularJS 的新手,我仍然没有得到这个凌乱、复杂的框架。
【问题讨论】:
标签: angularjs ng-view angularjs-rootscope