AngularJS fail to load module

后端 未结 6 1584
南方客
南方客 2021-01-04 04:43

EDIT: This only happens with IE (tested on IE10)

I have a app that loads fine initially, however, when refreshed it gives this error:

SCRIPT50

相关标签:
6条回答
  • 2021-01-04 05:01
    app.config(['$stateProvider', ($stateProvider) => {
      $stateProvider.state('login', {
        url: '/login',
        templateUrl: 'partials/login.html'
      }).state('dashboard', {
        url: '/dashboard',
        templateUrl: 'partials/dashboard.html'
      })
    }])
    

    In my case Internet Explorer didn't like the arrow functions. Changing these to function(){} notation fixed the issue:

    app.config(['$stateProvider', function ($stateProvider) {
      $stateProvider.state('login', {
        url: '/login',
        templateUrl: 'partials/login.html'
      }).state('dashboard', {
        url: '/dashboard',
        templateUrl: 'partials/dashboard.html'
      })
    }])
    
    0 讨论(0)
  • 2021-01-04 05:06

    We had the same issue only in IE. It was caused by a typo (some cat must have stepped on the keyboard):

    <script type=" text/javascript" src="assets/js/app.js"></script>
    

    The leading space in the value of the type-Attribute was causing the problem. As soon as it was removed the app worked fine again.

    0 讨论(0)
  • 2021-01-04 05:14

    I felt like and idiot when I found what I was doing wrong, but in case you're like me, then here are some other things to check first:

    1. Make sure the child module is loading first. In my case, I had to make sure that the child module was physically before my parent module. You can confirm this by putting a breakpoint on each module init line.
    2. Even with correct physical order, the execute order was still off. One of my modules was wrapped in a self-executing function, and the other was not. Doh.
    3. There was an error in the child function which actually caused this error to show twice in the console. This is because I use a syntax like this:

      var mod = angular.module("blah", []);
      mod.filter("filterName", function(){ ... }); 
      

      At one point I forgot the empty brackets when starting the module, so the line looked like this and threw this error:

      var mod = angular.module("blah");  // <-- wrong
      

    To recap, make sure the child module executes first and has no errors.

    0 讨论(0)
  • 2021-01-04 05:16

    By the way, using Angular 1.0.6, loading jQuery before angular (hardcoded script tags) causes IE10 to throw 'no Module' error.

    The only option I could find to correct it is to manually bootstrap and ensure my app.js that defines the module was loaded after all other child module references (like Barnabas mentioned).

    0 讨论(0)
  • 2021-01-04 05:17

    Ok I don't know why auto-bootstrapping is failing, but if I manually bootstrap the application it works fine.

    e.g.

    <html>
    
    ...
    
    <script src="js/app.js"></script>
    <script src="js/controller.js"></script>
    <script>angular.bootstrap(document, ['myAppModule']);</script>
    
    0 讨论(0)
  • 2021-01-04 05:21

    I had this very same problem, only in IE9. Lower versions of IE actually worked fine, as did newer browsers.

    Manually bootstrapping solved the problem, but threw an error "Unknown Provider" for a filter that is part of my module. Note that the filter still seemed to be functioning as expected.

    In the end, the solution that solved my problem and ceased the errors from being thrown at all was to simply rename the module file to be the same as the module.

    So if the name of my module was myAppModule then the filename should be myAppModule.js and not my_app_module.js.

    0 讨论(0)
提交回复
热议问题