Bomani Kernizan Bomani Kernizan - 5 months ago 78
AngularJS Question

UI routes not working

I can't seem to get my angular app to work with routes. The basic app itself works but breaks the moment I try to add in routes

Here's a link to the plunker: broken routes

var app = angular.module('appModule', ['ui.router']).config(['$stateProvider', '$urlRouterProvider',function($stateProvider, $urlRouterProvider) {


.state('home', {
url: '/home',
templateUrl: 'home.html'
controller: 'homeController'})}])

app.controller('homeController', ['$scope', function($scope) {$scope.hello = "flarg";}])

and here is the the same simple app without routes link to plunker here: working app


You configuration should be like this,

var myApp = angular.module("myApp", ['ui.router']);
myApp.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.when("", "/home");
    .state("home", {
      url: "/home",
      templateUrl: "home.html",
      controller: 'homeController'
myApp.controller('homeController', ['$scope', function($scope) {
  $scope.hello = "flarg";