Note that there are some explanatory texts on larger screens.

plurals
  1. POangular Failed to instantiate module
    primarykey
    data
    text
    <p>I am attempting to use require with angular</p> <p>I currently get the error</p> <pre><code>Failed to instantiate module </code></pre> <p>The exception url begins</p> <pre><code>http://errors.angularjs.org/undefined/$injector/modulerr? </code></pre> <p>When I look at my source using chrome dev tools and i expand my scripts folder the only file present at time of the error is app/main.js. None of the content from folders: controllers, modules, or routes are present. This would lead me to believe that this is a case of premature injection (not a real term). </p> <p>I have tried to ways to slow down the injection until the correct time, none have had an effect. </p> <p>first try </p> <pre><code>require(['jquery', 'angular', 'app/modules/app'], function ($, angular, app) { $(function () { // using jQuery because it will run this even if DOM load already happened angular.bootstrap(document, ['app']); }); }); </code></pre> <p>second attempt</p> <pre><code> require(['angular', 'app/modules/app'], function (angular, app) { var $html = angular.element(document.getElementsByTagName('html')[0]); angular.element().ready(function () { $html.addClass('ng-app'); angular.bootstrap($html, [app.name]); }); }); </code></pre> <p>third try</p> <pre><code> require(['angular', 'app/modules/app'], function (angular, app) { require(['Scripts/app/modules/app.js', 'Scripts/app/controller/controllers.js'], function (app) { angular.bootstrap(document.body, [app]); }) }); </code></pre> <p><b>UDPATE</b></p> <p>main.js</p> <pre><code> require.config({ baseUrl: '/Scripts/', urlArgs: "bust=" + (new Date()).getTime(), paths: { 'jquery': 'lib/require-jquery', 'angular': 'lib/angular/angular.min', 'angular-resource': 'lib/angular/angular-resource.min', }, shim: { 'angular': { 'exports': 'angular' }, 'angular-resource': { deps: ['angular'] }, 'jQuery': { 'exports': 'jQuery' }, } }); require(['jquery', 'angular', 'app/modules/app'], function ($, angular, app) { //the above methods go here }); </code></pre> <p><b>Update 2</b></p> <p>app.js</p> <pre><code>define([ 'angular', 'app/controllers/controller', 'lib/angular/angular-route' ], function (angular, controllers) { 'use strict'; var app = angular.module('app', [ 'app.controllers' ]); app.config(['$routeProvider', function ($routeProvider) { $routeProvider. when('/phones', { templateUrl: 'Templates/phone-list.html', controller: 'PhoneListCtrl' }). when('/phones/:phoneId', { templateUrl: 'Templates/phone-detail.html', controller: 'PhoneDetailCtrl' }). otherwise({ redirectTo: '/phones' }); }]); return app; }); </code></pre> <p>main.js</p> <pre><code>require.config({ baseUrl: '/Scripts/', urlArgs: "bust=" + (new Date()).getTime(), paths: { 'jquery': 'lib/require-jquery', 'angular': 'lib/angular/angular.min', 'angular-resource': 'lib/angular/angular-resource.min' }, shim: { 'angular': { 'exports': 'angular' }, 'angular-resource': { deps: ['angular'] }, 'jQuery': { 'exports': 'jQuery' }, 'app/modules/app': 'angular' }, dep: ['app'] }); require(['jquery', 'angular', 'app/modules/app'], function ($, angular, app) { angular.element(document).ready(function () { angular.bootstrap(document, ['app']); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload