TypeError:无法读取未定义
的属性'index'
var crud = angular.module('Crud', ['ngRoute']);
crud.config(['$routeProvider', function($routeProvider){
$routeProvider.when('/edit/:index', {
templateUrl: 'js/views/edit.html',
controller: 'EditCtrl'
}).when('/',{
templateUrl: 'js/views/list.html'
})
}]);
crud.controller('EditCtrl',['$scope', function(scope,$routeParams){
scope.name = scope.names[$routeParams.index];
}]);
为什么我的索引未定义。我的网址似乎很好,http://localhost:63342/Angular-CRUD/#/edit/2
似乎id正在从视图中正确传递,但为什么我getting index
在我的控制器中未定义。
答案 0 :(得分:2)
您尚未传递$routeParams
依赖
//here
crud.controller('EditCtrl',['$scope','$routeParams', function(scope,$routeParams){
scope.name = scope.names[$routeParams.index];
}]);