Look at the code first:
define(['angular','angular-touch'],function(angular){
'use strict';
return angular.module('weather-app',['ngTouch']);
});
Use requirejs to call this module to get the module defined by angularjs. It turns out that before the module definition of angular.module('weather-app',['ngTouch'])
has not been executed, an error message [$injector:modulerr] Failed to instantiate module weather-app due to:
has been reported... (breakpoint If it is set to 'use strict', an error will already be reported).
and found that the name of the module in the error message changes with the value of the attribute in the htmlng-app
file. However, if the weather-app
in the above js module code is changed to another value, it will not change. What a change. The entire stack of error prompts only involves angular.js
one resource file, and the others are files of plug-ins that come with the browser.
It seems that angular.js was executed immediately after being downloaded. The module definition in the define callback function body was not executed at all, so it started to check the angular instructions on the html tag, and tried to initialize ng-app, and found that ng -The name specified on the app has not been defined by the sentence angular.module('weather-app',['ngTouch']);
.
This reconfirms: the problem encountered before is the same.
At that time, angular and two other custom modules were loaded, with a total of three dependencies, and then the angular.module definition was executed.
After the custom module artificially inserts a long meaningless string, because it must wait for it to be loaded before defining angular.module(), angular loads before this and tries to initialize ng on the <html> tag -app and an error is reported.
So the solution I need is to not execute it immediately after angular.js is loaded, but to wait until the angular.module('weather-app',['ngTouch']) command is executed before proceeding. Handle ng-app on tags.
Don’t write
ng-app="weather-app"
, 然后再配合使用angular.bootstrap
on the page and it’s OKhttp://docs.ngnice.com/api/ng/function/angular.bootstrap