AngularJS,我的函数不会重定向到新页面

时间:2014-01-16 13:28:10

标签: angularjs path location

我的angularJs函数不会重定向到新页面,因为$ location未定义。

这是我的controller.js:

wikiControllers.controller('articleController', ['$scope', 'articleService', '$routeParams', '$sanitize', 
function($scope, articleService, $routeParams, $sanitize, $location){

$scope.deleteArticle = function(){
  //articleService.deleteArticle(this.article);
  $location.path("/hjem");
}
  }]);

.html中的我的按钮:

<button ng-click="deleteArticle()" ng-confirm-click="Er du sikker på at du vil slette dette?">Slett artikkel</button>

ng-confim-click也不会显示某种确认框。

1 个答案:

答案 0 :(得分:1)

因为您尚未向阵列添加$ location。试试这个:

wikiControllers.controller('articleController', ['$scope', 'articleService', '$routeParams', '$sanitize', '$location', 
function($scope, articleService, $routeParams, $sanitize, $location){

$scope.deleteArticle = function(){
  //articleService.deleteArticle(this.article);
  $location.path("/hjem");
}
  }]);