Reputation: 1147
I'm having an issue making route work:
angular_app.config(function($routeProvider){
$routeProvider.when('Title', {
controller : 'TitleController',
templateUrl : 'app/html/Title.html'
}).otherwise({
redirectTo : 'Title'
});
});
This will not fire correctly, however if I edit like so:
angular_app.config(function($routeProvider){
$routeProvider.when('/', {
controller : 'TitleController',
templateUrl : 'app/html/Title.html'
}).otherwise({
redirectTo : 'Title',
controller : 'TitleController',
templateUrl : 'app/html/Title.html'
});
});
It does fire my controller, but it does it twice. Why does it not work on the first case?.
My app will have it's entry point on my Title.html file.
Any tips?
Upvotes: 0
Views: 73
Reputation: 387
You should change your code to this.
angular_app.config(function($routeProvider){
$routeProvider.when('/title', {
controller : 'TitleController',
controllerAs: 'Title',
templateUrl : 'app/html/Title.html'
}).otherwise({
redirectTo : '/title'
});});
Upvotes: 0
Reputation: 171698
Need to read the documentation a little closer.
The first argument needs to be the path with a leading /
. Also redirectTo
should also be a path that is already declared in a when()
angular_app.config(function($routeProvider){
$routeProvider.when('/title', {
controller : 'TitleController',
templateUrl : 'app/html/Title.html'
}).otherwise({
redirectTo : '/title'
});
});
Upvotes: 2