0

I have built a simple angular and am trying to implement ui-router and specifically, $UrlRouteProvier.otherwise to redirect to a certain url if something nonexistent is entered. I am getting the following exception when trying to load my page now and can't seem to find the error. All help is appreciated. Code and error below.

Angular app:

var app = angular.module('myApp', ['ui.router','ngAnimate', 'ui.bootstrap']);

app.config(['$urlRouterProvider', '$stateProvider', function($urlRouterProvider, $stateProvider){
    $urlRouterProvider.otherwise('/browse/overview.html');
}])

error:

Failed to instantiate module myApp due to:
Error: [$injector:nomod] http://errors.angularjs.org/1.3.4/$injector/nomod?p0=gcIm...
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:6:416
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:21:334
    at a (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:20:483)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:21:218
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:35:76
    at r (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:7:302)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:34:428)
    at Lb (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:38:146)
    at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:17:339

note: everything works fine if I remove ui.router from the list of dependencies

1
  • Unrelated note: version 1.3.4 of Angular is quite old. You'd better use the most recent version. Commented Mar 8, 2016 at 21:28

2 Answers 2

2

It looks like you don't have ui-router code loaded. Try to include:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script>
Sign up to request clarification or add additional context in comments.

3 Comments

Make sure to load the ui-router library before you reference it in your Angular code
@m1gu3l I accepted your answer because it fixed the error however routeproverider.otherwise is not redirecting to the page I specified. I am getting an empty page with not found on it when entering a random url such as localhost:8081/browse/overvieasdsw.html
I assumed it's not complete solution and you focus on injection problem. Try to define state with templateUrl pointing to browse/overview.html and then redirect to that state's url. Hope this helps.
0

Try writing your config line like this:

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

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.