【问题标题】:How can I change the CSS property of multiple input field using multiple ng-app in HTML?如何在 HTML 中使用多个 ng-app 更改多个输入字段的 CSS 属性?
【发布时间】:2019-02-15 15:08:57
【问题描述】:
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> 
</script>
<body>

<p>Change the value of the input field:</p>
<div ng-app="" ng-init="myCol=''">
<input style="background-color:{{myCol}}" ng-model="myCol">
</div>

<div id="secondApp" ng-init="myCo=''">
<input style="background-color:{{myCo}}" ng-model="myCo">
</div>
<p>AngularJS resolves the expression and returns the result.</p>
<p>The background color of the input box will be whatever you write in the input field.</p>
<script type="text/javascript">
 var secondDiv = document.getElementById('secondApp');  
 angular.element(document).ready(function() {  
          angular.bootstrap(secondDiv, [ 'secondApp' ]);  
   });
</script>
</body>
</html>

这是我的代码。第一个输入字段可以正常工作,但即使我使用引导程序,第二个输入字段也无法正常工作。请任何人告诉我正确的方法。 谢谢

【问题讨论】:

    标签: javascript html css angularjs


    【解决方案1】:

    Ajinkya 为您指明了正确的方向......从那里继续:

    var firstApp = angular.module("firstApp", []);
    var secondApp = angular.module("secondApp", []);
    
    firstApp.controller("faController", function($scope) {});
    secondApp.controller("saController", function($scope) {});
    
    angular.element(document).ready(function() {
      angular.bootstrap(document.getElementById("firstApp"), ['firstApp']);
      angular.bootstrap(document.getElementById("secondApp"), ['secondApp']);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
    
    <p>Change the value of the input field:</p>
    <div id="firstApp" ng-controller="faController" ng-init="myCol='lightblue'">
      <input style="background-color:{{myCol}}" ng-model="myCol">
    </div>
    
    <div id="secondApp" ng-controller="saController" ng-init="myColor2='lightpink'">
      <input style="background-color:{{myColor2}}" ng-model="myColor2">
    </div>
    
    <p>AngularJS resolves the expression and returns the result.</p>
    <p>The background color of the input box will be whatever you write in the input field.</p>

    【讨论】:

      【解决方案2】:

      这个问题已经有了答案:

      bootstrap to use multiple ng-app

      请参考并相应地更改您的代码。

      【讨论】:

      • 感谢您的回复.. 但我试过但我无法从那里理解如何在我的输入样式中使用它们?你会编辑我的代码吗?
      • @Akber Iqbal 给出的答案是我想说的:-)
      • @Ravi Kadyan 你现在可以结束这个问题了。
      • 对不起兄弟,我是新来的,如何关闭它?
      • 抱歉,您现在无法关闭您的问题,因为关闭问题需要一些声誉。
      猜你喜欢
      • 1970-01-01
      • 2012-06-24
      • 1970-01-01
      • 2021-12-07
      • 2012-06-19
      • 1970-01-01
      • 2015-12-06
      • 2014-10-20
      • 2016-07-12
      相关资源
      最近更新 更多