Alon Alon - 3 months ago 8x
AngularJS Question

angular-ui-router doesn't work

I doesn't manage to route using ui-router. It does work for me with ng-route, so I must have missed something basic. There is no error but I don't get any view.

The following code does not work (except for the otherwise statement):

angular.module("employeesApp", ["ui.router"])
.config(function ($stateProvider, $urlRouterProvider) {
.state('employeeList', {
url: "/employees",
templateUrl: "components/employee_list/employeeListView.html",


The following code does work:

angular.module("employeesApp", ["ngRoute"])
.config(function ($routeProvider) {
var employeeListRoute = {
templateUrl: "components/employee_list/employeeListView.html"

var otherwiseRoute = employeeListRoute;

.when("/employeeList", employeeListRoute)

Here is my index.html (omitted not relevant elements):

<!DOCTYPE html>
<html lang="en" ng-app="employeesApp">
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>

<script src="app.route.js"></script>
<script src="components/employee_list/employeeListCtrl.js"></script>
<ng-view />

What am I doing wrong when trying to use ui-router?


As @AminMeyghani already said, you should be using ui-view instead of ng-view directive to get router know that relative view should be loaded inside ui-view directive


Demo here