这是我的js代码
var MYApp = angular.module('myApp', ['ngRoute', 'myAppServices', 'ngSanitize'])
.config(myRouter);
angular.module('myAppServices', ['ngResource'])
.factory('GridsAPI', function($resource) {
return {
GetUser: $resource('/MY/system/getUser/:id')
};
});
function ViewUserController($scope, user) {
}
function myRouter($routeProvider) {
$routeProvider
.when('/users/view/:id', {
templateUrl: '/MY/system/users/view/:id',
controller: 'ViewUserController',
resolve: {
user: function(GridsAPI) {
//how to return user based on id passed to this url?
}
}
});
}
我想在加载视图之前通过ajax调用获取用户,如何解析id参数?
答案 0 :(得分:2)
注入$route
然后:
resolve: {
user: ['$route', 'GridsAPI', function($route, GridsAPI) {
var userId = $route.current.params.id;
...
}]
}