2017-08-04 222 views
1

我想重新加载我的管理页面,我知道角有$window.location.reload()$route.reload()。我试图通过注入$window到函数的PARAMS

scope.uploadList = function($window) { 
//... 
$window.location.href = /#/admin'; 
} 

成功提示信息下使用$window.location.reload()但我还是收到一条

Cannot read property 'location' of undefined 

不知道在哪里可以从这里走一个错误。我已经在指令中添加了这个。

+0

你确定你是注入'$ window'到你的指令成功 – AGE

+0

为什么不使用$ location.path? – Ohjay44

回答

2

您将需要在控制器中注入$window而不是在方法中,它将起作用。

2

你应该在控制器代码注入$window像下面

angular.module('windowExample', []) 
    .controller('ExampleController', ['$scope', '$window', function($scope, $window) { 
     $scope.greeting = 'Hello, World!'; 
     $scope.doGreeting = function(greeting) { 
     $window.alert(greeting); 
     }; 
    }]); 

没有在功能上虽然!

+0

我获得了很好的成功,但是我试图提取的项目仍然不会显示,除非我重新加载页面。有什么想法吗? – user2914144

+0

你打算如何取物品?你能告诉我那个代码吗? – Rahul

0

$window是不是你需要使用全局参考

window.location.href = '/#/admin'; 
0

进样$窗口到任何控制器的,像这样的对象:那么你将有机会获得浏览器窗口对象。

angular 
    .module('app', []) 
    .controller('MainController', ['$window', function($window) { 
     var vm = this; 
     vm.hello = 'Hello, Universe!'; 
     $window.alert(hello); 
     $window.location.reload(); 
     $window.location.href = '/#/admin'; 
    }]); 
1

尝试使用$location。这是用angularjs构建的,用于导航。确保将其注入为依赖项。

$location.path('/admin') 
0

我使用$ location.path(“URL),但如果你已经是那个特定的页面上没有做任何事情,所以我在routing.js做了第二次路由去影响在同一页“重装”的页面,我不知道这是你要什么尽管

例如:。。?

 .when('/Login', 
     { 
      templateUrl: 'Partials/LoginCustomer.html', 
      controller:'loginController'  
     }) 
     .when('/Login2', 
     { 
      templateUrl: 'Partials/LoginCustomer.html', 
      controller:'loginController'  
     }) 
+0

您不必创建新路线就可以强制重新加载 – Ohjay44