我这里有一个简单的代码,并且在传递参数时遇到困难。这是代码:
route.js
function config($routeProvider) {
$routeProvider
.when('/edit/:id', {
controller: 'UpdateTodoCtrl',
templateUrl: 'app/views/edit-todo.html'
});
}
的index.html
<div ng-controller="SomeOtherCtrl">
<table>
<tr ng-repeat="t in todos">
<a href="#/edit/{{ t.id }}">{{ t.name }}</a>
</tr>
</table>
</div
控制器
function UpdateTodoCtrl($http, $scope) {
function init() {
$scope.todos = null;
$scope.loading = true;
$http.get('app/endpoints/edit-todo.php', {
params: { todoId: //how to get the id paramter }
});
}
}
正如你在controller
中所说的那样,我评论了我的问题部分。如何使用$http.get
在我的网址中传递ID?谢谢。
答案 0 :(得分:2)
您的:id
是路线参数,因此您可以这样做:
function UpdateTodoCtrl($http, $scope, $routeParams) {
function init() {
$scope.todos = null;
$scope.loading = true;
$http.get('app/endpoints/edit-todo.php', {
params: { todoId: $routeParams.id }
});
}
}