Angularjs 如何使用routeParams进行路由?
只是尝试用一个简单的exp找出routeParams: app.js:Angularjs 如何使用routeParams进行路由?,angularjs,Angularjs,只是尝试用一个简单的exp找出routeParams: app.js: var app = angular.module("myApp", ['ngRoute']); app.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/routePerson/:personId', { templateUrl: 'person.html', controller: 'sh
var app = angular.module("myApp", ['ngRoute']);
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/routePerson/:personId', {
templateUrl: 'person.html',
controller: 'showCtrl'
}).
otherwise({
redirectTo: 'index.html'
});
}]);
app.controller('showCtrl', function($scope, $http, $routeParams) {
$http.get('data.json').
success(function(data){
$scope.names = data;
$scope.names_id = $routeParams.personId;
});
});
当我单击其中一个链接名称时,我将获得所有名称,而不是所选对象id的名称。。如何获取单击的对象id的对象名称
更清楚地说:
提前通知 您获得了正确的ID。您只需要在html中打印它
<span>Person ID - {{names_id}}</span>
Person-ID-{{names\u-ID}
如果您希望根据所选ID命名,请执行以下操作:
<span ng-repeat="t in names" ng-if="t.id == names_id"> {{t.name}} </span>
{{t.name}