Reputation: 5677
TypeError: Cannot read property 'index' of undefined
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];
}]);
Why am i getting index undefined. My url seems to be fine, http://localhost:63342/Angular-CRUD/#/edit/2
It seems that id is passing correctly from view, but why am i getting index
undefined in my controller.
Upvotes: 0
Views: 8131
Reputation: 133403
You have not passed $routeParams
in dependency
//here
crud.controller('EditCtrl',['$scope','$routeParams', function(scope,$routeParams){
scope.name = scope.names[$routeParams.index];
}]);
Upvotes: 2