0

I'm writing a plugin that uses Angularjs. I've loaded Angularjs and ngRoute locally:

wp_enqueue_script('angularjs',plugins_url('/js/angular.min.js', __FILE__ ),array(),'',true);
wp_enqueue_script('angularjsroute',plugins_url('/js/angular-route.min.js', __FILE__ ),array('angularjs'),'',true);

I have angularjs listed as a dependency for ngRoute so Angular loads first. However, I still get the error that says it's not loading:

Error: [$injector:nomod] Description This error occurs when a module fails to load due to some exception. The error message above should provide additional context.

Using ngRoute In AngularJS 1.2.0 and later, ngRoute has been moved to its own module. If you are getting this error after upgrading to 1.2.x or later, be sure that you've installed ngRoute.

Monkey-patching Angular's ng module This error can also occur if you have tried to add your own components to the ng module. This has never been supported and from 1.3.0 it will actually trigger this error. For instance the following code could trigger this error.

angular.module('ng').filter('tel', function (){}); Instead create your own module and add it as a dependency to your application's top-level module. See #9692 and #7709 for more information

I only get the ngRoute error when I place ng-app="myPlugin" to a containing div.

When I check the output of my page I can verify that angularjs is loading first per this answer.

Community
  • 1
  • 1
dcp3450
  • 10,959
  • 23
  • 58
  • 110

1 Answers1

0

Have you tried keeping it simple? I usually declare my scripts in functions.php like this:

    wp_enqueue_script(
        'angularjs',
        get_stylesheet_directory_uri() . '/js/angular.min.js'
    );

    wp_enqueue_script(
        'angularjs-route',
        get_stylesheet_directory_uri() . '/js/angular-route.min.js'
    );
spik3s
  • 1,189
  • 2
  • 11
  • 27