8

I try to use angular ui-router in my web app but I have problem. Here is the app directory:

  test-app
  |_ bower-component
  |_ app
     |_ views
     |_ index.html
     |_ scripts
        |_ app.js 

and in app.js:

angular
  .module('testApp', [
    'ngAnimate',
    'ngAria',
    'ngCookies',
    'ngMessages',
    'ngResource',
    'ui.router',
    'ngSanitize',
    'ngTouch'
  ])
  .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/');  
    $stateProvider
      .state('home',{
        url: '/',
        templateUrl: 'index.html',
        controller: 'MainCtrl'
      })
   .
   .
   .

But when I run the app, I get this error on console:

WARNING: Tried to load angular more than once
3
  • 1
    You want your template to be a partial and not the index. Commented Mar 16, 2015 at 7:16
  • Sorry I can't understand what you say ! Commented Mar 16, 2015 at 7:21
  • 1
    You want - templateUrl: 'home.html' Commented Mar 16, 2015 at 7:24

2 Answers 2

11

Your webserver loads the index.html file, but then you load it again in the view with

templateUrl: 'index.html'

So I think you intended that to be a different template. What you have here causes the index HTML file to be loaded inside itself, including the angular script tags, causing that error.

Sign up to request clarification or add additional context in comments.

Comments

0

Using reqire('./path/angular.min.js') will solve any problem related to loading it more then once.

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.