I've encountered an issue with ui-router functionality in my code. Here's a breakdown of the problem:
Within my index.html file
<li> <a ui-sref="day2">Day 2</a> </li>
<li><a ui-sref="day3">Day 3</a></li>
<li><a ui-sref="day4">Day 4</a></li>
In my main.js file
var myModule = angular.module('myApp', ['ngMessages', 'ui.router']);
myModule.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/day1");
$stateProvider
.state('day1', {
url: '/day1',
templateUrl: 'index.html'
})
.state('day1.example', {
url: '/theview',
template: '<h3>I am a routed view</h3>'
})
.state('day2', {
url: '/day2',
views: {
// Main template placement
'': {
templateUrl: 'day2.html'
}
}
})
.state('day3', {
url: '/day3',
views: {
// Main template placement
'': {
templateUrl: 'day3.html'
},
// Defining child views
'directives@day3': {
templateUrl: 'directives.html'
},
// Separate controller defined for column two
'services@day3': {
templateUrl: 'service.html'
}
}
})
.state('day4', {
url: '/day4',
views: {
'': {
templateUrl: 'day3.html'
}
}
});
});
Upon clicking the links for day 2, day 3, and day 4 in the browser, nothing seems to happen. Additionally, the 'day1.example' state does not work as expected even though it is called from the index.html file like this:
<div>
<a ui-sref=".example" class="save button">Example</a>
</div>
<div ui-view> </div>
</div>
The issue remains unresolved and I'm uncertain about where the problem lies. I have already downloaded the minified ui-router file, so that should not be causing any issues. The day1 route is detected correctly in the browser at
file:///Users/Projects/AngularJs/index.html#/day1
I followed the tutorial on Scotch.
A specific concern arises when using templateUrl: 'day2.html'
. Changing it to
template: '<h1> Check if it Works </h1>'
makes the link for day 2 function properly.