【发布时间】:2016-10-05 22:05:55
【问题描述】:
我是 angularJS 的新手。我正在使用 angularjs 来实现一个网站。该网站有两个页面。第一个页面列出了所有项目,如果用户点击它,它将重定向到详细信息页面。
我的路线配置如下:
var app = angular.module('myApp', ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/list", {
templateUrl : "list.html",
controller : "listCtrl"
})
.when("/detail/:id"){
templateUrl : "detail.html"
}
});
在 list.html 中。我使用 ng-repeat 来显示一个项目列表和一个监听器来监听鼠标点击。
<ul class="list-group">
<li class="list-group-item" ng-repeat="i in items">{{i.name}}
<a href="#" ng-click="goToEdit($index)">
<span class="glyphicon glyphicon-pencil"></span>
</a>
</li>
</ul>
我想将视图重定向到 ng-click 功能中的详细信息。
我试过$location.path(),但它不起作用。
$scope.goToEdit = function(index){
console.log($location.path());
$location.path("/detail/" + index);
console.log($location.path());
}
这种方式行不通。 即使第二次登录控制台显示 location.path() 已更改为“/detail/id”。
如果我在$location.path(); 之后添加$scope.$apply() 那么我会得到一个动作已经在进行中的错误。
你有什么办法吗???
谢谢
【问题讨论】:
-
让我看看你的控制器,你在注入什么?
-
你能在 Plunker 中重现这个问题吗?
标签: angularjs