javascript - "Uncaught Error: [$injector:modulerr] Failed to instantiate module" when there are multiple "ng-app" directives -
i learning angularjs , , while experimenting met error:
uncaught error: [$injector:modulerr] failed instantiate module myapp due to: error: [$injector:nomod] module 'myapp' not available! either misspelled module name or forgot load it. if registering module ensure specify th......0)
here code:
<!doctype html> <html > <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.js"></script> <script type="text/javascript"> function controller( $scope, $location ){ // } function controller2( $scope, $location ){ // } </script> <title>angular js application</title> </head> <body > <div ng-app="myapp"> <div ng-controller='controller' > <h1>app1</h1> </div> </div> <div ng-app="myapp2"> <div ng-controller='controller2' > <h1>app2</h1> </div> </div> </body> </html>
can explain,what problem?
you have no module bind. add following code js , should fine
var mymodule = angular.module('myapp', []); var mymodule2 = angular.module('myapp2', []);
update
you can use on ng-app per html auto bootstrap application you, can run more 1 app per page manually bootstrap app module...
here plunker example show both manually , auto module bootstraping...
Comments
Post a Comment