0

I'm using ui.router for routing in my Angular app. This is a very simple app which have only 3 views: Home , FAQ and Contact. I have define 3 different states for each page and define their template url, but no navigation is working at all. No view template is loaded into my index.html. I am attaching the following code

var app = angular.module('app', ['ui.router'])


app.config(['$stateProvider,$urlRouterProvider',function($stateProvider, $urlRouterProvider) {
	
	$urlRouterProvider.otherwise('/home');
	$stateProvider.state('home',{
		url:'/home',
		templateUrl:'Home.html'
	}).state('contact',{
		url:'/contact',
		templateUrl:'Contact.html'
	}).state('faq',{
		url:'/faq',
		templateUrl:'FAQ.html'
	})
}]);
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script>
<nav class="navbar navbar-inverse" role="navigation">
		<div class="navbar-header">
			<a class="navbar-brand" ui-sref="#">AngularUI Router </a>
		</div>
		<ul class="nav navbar-nav">
			<li><a ui-sref="home">Home</a></li>
			<li><a ui-sref="faq">FAQ</a></li>
			<li><a ui-sref="contact">Contact</a></li>
		</ul>
	</nav>
	<div class="container">
		<div ui-view></div>
	</div>

and my views are very simple one, for example Home.html

<div>
    Home Page!
</div>
2
  • Check that the path for templateUrl is correct. If you have the templates inside a folder the templateUrl should be templates/Home.html Commented Mar 9, 2016 at 8:45
  • the path is correct, I even stop using templateUrl and use template instead so my code is something like this: url:'/home', template: '<div>Home Page!</div>' Commented Mar 9, 2016 at 8:47

2 Answers 2

2

You forgot to close your dependencies quotes:

Just change

app.config(['$stateProvider,$urlRouterProvider',

To

app.config(['$stateProvider','$urlRouterProvider',

Plunker

Sign up to request clarification or add additional context in comments.

1 Comment

@Brk When this solved your issue, please mark this answer as the right one. I think you now only upvoted.
0

Even I faced the same problem in the beginning. I solved it by running the application on a local server.

You can use brackets editor which has an inbuilt server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.