I have a simple web project that has a phone list and each element in that list contains a phone detail information. If I clicked on a phone id, it should bring me to a page for that phone only, however, nothing happened after a phone id was clicked.
When the app was loaded, it went to the index page with a url:
http://localhost:8080/angular-route-multiple-views/index.html#!/phones
After I clicked on the first phone id, the url was changed to the following but it didn't go to that page at all:
http://localhost:8080/angular-route-multiple-views/index.html#!/phones#%2Fphones%2Fnexus
Can someone please help and let me know why it didn't go to the phone detail page ? Thanks.
index.html
<!DOCTYPE html>
<html ng-app="mainModule">
<head>
<meta charset="ISO-8859-1">
<title>AngularJS Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-route.js"></script>
<script src="js/main-module.js"></script>
<script src="js/phonelist-module.js"></script>
<script src="js/phonelist-component.js"></script>
<script src="js/config.js"></script>
<script src="js/phonedetail-module.js"></script>
<script src="js/phonedetail-component.js"></script>
</head>
<body>
<div ng-view></div>
</body>
</html>
main-module.js:
angular.module('mainModule', ['ngRoute', 'phoneList', 'phoneDetail']);
config.js:
angular.module('mainModule').
config(['$locationProvider', '$routeProvider',
function config($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
$routeProvider.
when('/phones', {
template: '<phone-list></phone-list>'
}).
when('/phones/:phoneId', {
template: '<phone-detail></phone-detail>'
}).
otherwise('/phones');
}
]);
phonelist-module.js:
angular.module('phoneList', ['ngRoute']);
phonelist-component.js:
angular.module('phoneList').component('phoneList', {
templateUrl: 'js/phone-list.template.html',
controller: function PhoneListController() {
this.phones = [
{
id: 'nexus',
name: 'Nexus S',
snippet: 'Fast just got faster with Nexus S.',
},
{
id: 'motorola-xoom',
name: 'MOTOROLA XOOM™',
snippet: 'The Next, Next Generation tablet.',
}
];
}
});
phonedetail-module.js:
angular.module('phoneDetail', ['ngRoute']);
phonedetail-component.js:
angular.module('phoneDetail').
component('phoneDetail', {
template: 'TBD: Detail view for <span>{{$ctrl.phoneId}}</span>',
controller: ['$routeParams',
function PhoneDetailController($routeParams) {
this.phoneId = $routeParams.phoneId;
}
]
});
phone-list.template.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Phone List</title>
</head>
<body>
<li ng-repeat="phone in $ctrl.phones" >
<a href="#/phones/{{phone.id}}">{{phone.name}}</a>
<p>{{phone.snippet}}</p>
</li>
</ul>
</body>
</html>
<a ng-href="#/phones/{{phone.id}}">{{phone.name}}</a>