我是Angular.js的新手......基于id,fullPostController使用$ http获取所需的数据,但我应该如何将postId传递给控制器?
'use strict';
var myAPP = angular.module('myAPP', [ 'ngRoute' ]);
myAPP.config(['$routeProvider',
function (
$routeProvider
) {
$routeProvider.
when('/', {
templateUrl: 'pages/home.html',
controller: 'mainController'
}).
when('/post/:postId', {
templateUrl: 'pages/full_post.html',
controller: 'fullPostController'
}).
otherwise({
redirectTo: '/'
});
}]);
如何将postId传递给fullPostController?
答案 0 :(得分:1)
在控制器中注入$ routeParams,帖子ID为$ routeParams.postId