2

**This js file for the ui router is proper or not.The error displaying is "Error: Unknown provider: $stateProvider from routerApp"

this js files have been loaded in the Html file.

**

var routerApp = angular.module('routerApp', ['ui.router']);

routerApp.config(function($stateProvider, $urlRouterProvider) {

$urlRouterProvider.otherwise('/template1');

$stateProvider

    // HOME STATES AND NESTED VIEWS ========================================
    .state('template1', {
        url: '/temp1',
        templateUrl: 'templates/template1.html'
    })

    // ABOUT PAGE AND MULTIPLE NAMED VIEWS =================================
    .state('template2', {
        // we'll get to this in a bit       
    });

});


<!-- MAIN CONTENT -->
<div class="container">

<!-- THIS IS WHERE WE WILL INJECT OUR CONTENT ============================== -->
<div ui-view></div>

</div>

</body>
</html>

Please help.Thanks in advance

2
  • The js files that are loaded are:<script src="cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.0.1/…> <script src="ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-animate.min.js"></script> <script src="app_js.js"></script> Commented Aug 13, 2014 at 14:00
  • Are you also including angular.js file? and make sure ui.router js file is loaded after angular.js. Commented Aug 13, 2014 at 14:04

2 Answers 2

2

please see here : http://plnkr.co/edit/FYxpaHpKgvpEu6f1TZ7l?p=preview

var routerApp = angular.module("routerApp", ["ui.router"]);



routerApp.config(
  ["$stateProvider", "$urlRouterProvider",
    function($stateProvider, $urlRouterProvider) {

      $urlRouterProvider.otherwise("/template1");

      $stateProvider
        .state("template1", {
          url: "/template1",
          templateUrl: "template1.html",
          controller: "tmp1Controller"
        })
        .state("template2", {
          url: "/template2",
          templateUrl: "template2.html",
          controller: "tmp2Controller"
        })



      ;

    }
  ]);

routerApp.controller("mainCtrl", ["$scope",
  function($scope) {

  }
]);
routerApp.controller("tmp1Controller", ["$scope",
  function($scope) {

  }
]);

routerApp.controller("tmp2Controller", ["$scope",
  function($scope) {

  }
]);
Sign up to request clarification or add additional context in comments.

Comments

1

I had the same problem, was solved replacing

<div ui-view></div>

by

<ui-view> 
 <i>Loading ....</i>
</ui-view>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.