w2olves w2olves - 1 month ago 6
AngularJS Question

Why is this simple UI-Router example not working?

I feel guilty about asking such a question...Still, here goes
I have a fairly basic UI-Router example, however for the life of me I am not able to get it to work.

The body looks like this:

<body>
<nav class="navbar navbar-inverse">
<div class="container">
<a ui-sref="home" class="navbar-brand">My Product</a>
</div>
</nav>
<div class="container">
<div ui-view></div>
</div>
</body>


The app. js module looks like this

(function(){
//Module Declaration
var app = angular.module("movieViewer", ["ui.router"]);


app.config(["$stateProvider", "$urlRouterProvider",
function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/");
$stateProvider
.state("home", {
url: "/",
templateUrl: "main.html",
// controller: "MainCtrl",
})
}
]);

}());


Fairly simple, however it doesnt work. Will appreciate any heads up on this.

Plunk here

Answer

You need to kick off angular on page by adding ng-app directive with module name movieViewer on html tag.

ng-app="movieViewer"

Demo Here