2

Facing some strange with ui-router angularjs. I am configuring an single page application using these frameworks. Here is my code

function initWmappConfig($stateProvider, $locationProvider, $compileProvider) {
    $locationProvider.html5Mode(true);
    $stateProvider.
        state('login', { url: '/', templateUrl: '/Views/login', controller: 'login-controller', controllerAs: 'vm' })
        .state('register', { url: '/register', templateUrl: '/Views/Register', controller: 'login-controller', controllerAs: 'vm' });

    $stateProvider.state('otherwise', {url: '/'});

    $compileProvider.debugInfoEnabled(false);
}

If i am using this above configuration i am facing this war

WARNING: Tried to load angular more than once

but on other hand if i simple change

$locationProvider.html5Mode(false);

then everything seems to work just fine...

Please let me know why this is happening.

Thanks

2 Answers 2

1

It's because you didn't mention the .html extension in the templateUrl

  state('login', { url: '/', templateUrl: '/Views/login.html', controller: 'login-controller', controllerAs: 'vm' })
  .state('register', { url: '/register', templateUrl: '/Views/Register.html', controller: 'login-controller', controllerAs: 'vm' });

Also for otherwise, you need to use $urlRouterProvider

$urlRouterProvider.otherwise('/');
Sign up to request clarification or add additional context in comments.

1 Comment

i am handling the extension on server side...i mean on route change one server side event will fire and checking the route and adding .cshtml extension to it..
0

I was getting this error. The reason behind this is the use of jQuery.

<script src="http://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="/public/vendor/angular/angular.js" type="text/javascript"></script>
<script src="/public/vendor/angular/angular-route.js" type="text/javascript"></script>

I removed the following and warning disappeared:

<script src="http://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>

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.