多个ng-app问题

时间:2016-08-02 16:26:48

标签: javascript angularjs ng-app

Html文件

<!DOCTYPE html>
<html >
    <head>
        <title>Angular JS Demo</title>
        <script src="scripts/angular.min.js"></script> 
        <script src="scripts/Script_1.js"></script>
        <meta charset="utf-8" />
    </head>
    <body>
        <div  ng-app="HelloWorldApp" ng-controller="HelloWorldController">
            Message: {{ greeting }}
        </div>
        <div id="class2" ng-controller="HelloWorldController1">
           Message: {{ message }}
         </div>
    </body>
</html>

Script_1.js

/// <reference path="angular.min.js" />
angular.module('HelloWorldApp', []).controller("HelloWorldController", function ($scope) {
   $scope.greeting = "Hello World";
});

angular.module('HelloWorldApp1',[]).controller("HelloWorldController1",function ($scope) {
   $scope.message = "Hello World";
});
angular.bootstrap(document.getElementById('class2'), ['HelloWorldApp1']);

The output is 
     Message: Hello World
     Message: {{ message }}

虽然我使用了angular.bootstrap(document.getElementById('class2',[HelloWorldApp1]); 为什么它不是bootstrapping。我是这个anugular js的新手,我错过了任何库吗? 我被困在这里。请帮助我。

谢谢

1 个答案:

答案 0 :(得分:0)

试试这个:

  <!DOCTYPE html>
    <html >
        <head>
            <title>Angular JS Demo</title>
            <script src="scripts/angular.min.js"></script> 
            <script src="scripts/Script_1.js"></script>
            <meta charset="utf-8" />
        </head>
        <body>
            <div  ng-app="HelloWorldApp" ng-controller="HelloWorldController">
                Message: {{ greeting }}
            </div>
            <div id="class2"ng-app="HelloWorldApp1" ng-controller="HelloWorldController1">
               Message: {{ message }}
             </div>
        </body>
    </html>