patrick patrick - 4 months ago 10
Javascript Question

Angular JS ui-router not loading view

I am having trouble with my Angular JS ui-router and every question I have found on here shows a solutions I have already tried.

In my ui-view-tag my actual template is not displayed.

<body ng-app="myApp">
<div class="row">
<div class="col-md-6 col-md-offset-2">
<ui-view></ui-view>
</div>
</div>
</body>


This is my app.js

angular.module('myApp', ['ui.router'])
.config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {

$stateProvider
.state('home', {
url: '/',
templateUrl: 'home.html',
controller: 'MainCtrl'
})

$urlRouterProvider.otherwise('home');
}])


Thank you very much everybody, I would really appreciate a short feedback on that.

Answer

The $urlRouterProvider otherwise() accepts the url path you want to redirect to. Therefore you must change:

$urlRouterProvider.otherwise('home');

To:

$urlRouterProvider.otherwise('/');