Ernest Ernest - 6 months ago 50
AngularJS Question

Using TemplateUrl doesn`t work

Hello i have a problem with my code. When i click on link page isn`t reload.

Here is a HTML and JS code:



var app=angular.module('mainApp',['ngRoute']);
app.config(function($routeProvider){
$routeProvider
.when('/',{
templateUrl: 'home.html'
})
.when('/about',{
templateUrl: 'about.html'
});
.when('/contact',{
templateUrl: 'contact.html'
});
.otherwise({ redirectTo: '/'});
});
app.controller('mainCtrl',function($scope){

});

<div ng-controller="mainCtrl">
<div>
<nav>
<ul>
<li><a href="#/">Home</a></li>
<li><a href="#/about">About us</a></li>
<li><a href="#/contact">Contact</a></li>
</ul>
</nav>
</div>
<br/>
<div ng-view >

</div>
</div>





Have you any idea what`s wrong?

Answer

Remove semicolon (;) for second and thirs .when cases

var app=angular.module('mainApp',['ngRoute']);
app.config(function($routeProvider){
  $routeProvider
      .when('/',{
            templateUrl: 'home.html'
      })
      .when('/about',{
            templateUrl: 'about.html'
      })
      .when('/contact',{
            templateUrl: 'contact.html'
      })
      .otherwise({ redirectTo: '/'});
});
Comments