I came across with Angular routing example when I'm following a tutorial. I tried as the tutorial but it won't work. But when I copied the code from the tutorial it works perfectly. Can anyone help me with this.
This is my main page
<div ng-controller="routingCtrl">
<div>
<ul>
<li><a href="#home">Home</a> </li>
<li><a href="#other">Oher</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div>
<p>{{message}}</p>
</div>
<ng-view></ng-view>
</div>
</div>
And this is my script file called script.js
var routingApp = angular.module('sampleRouting', ['ngRoute'])
.controller('routingCtrl', function ($scope) {
$scope.message = "Main Page";
})
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'home.html',
controller: 'homeCtrl'
})
.when('/other', {
templateUrl: 'other.html',
controller: 'otherCtrl'
})
.when('/contact', {
templateUrl: 'contact.html',
controller: 'contactController'
})
.otherwise({ redirectTo: '/' });
})
.controller('homeCtrl', function ($scope) {
$scope.homeMessage = "Welcome to home !"
})
.controller('otherCtrl', function ($scope) {
$scope.otherMessage = "Welcome to other !"
})
.controller('contactController', function ($scope) {
$scope.contactMessage = "Welcome to Contacts !"
})
And this is other.html
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Other two home.html and contact.html also contains random texts like this.
The problem is home.html view has loaded into the index.html at the beginning of the but when I clicked hyperlinks to Other and Contact the content won't chance. As the home.html has loaded I think ngRoute works well. But other two won't work. Can anyone help me to solve this issue? Thanks a lot.