简体   繁体   English

多个ng-app问题

[英]Multiple ng-app issue

Html file 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 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 }}

Though I used the angular.bootstrap(document.getElementById('class2',[HelloWorldApp1]); Why it is not bootstrapping.I am new to this anugular js,am I missing any libraries? I am stuck here.Pls help me. 虽然我使用了angular.bootstrap(document.getElementById('class2',[HelloWorldApp1]);为什么它不是bootstrapping。我是这个anugular js的新手,我错过了任何库吗?我被困在这里。请帮助我。

Thank you 谢谢

Try this: 尝试这个:

  <!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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM