Как я могу изменить свойство CSS для нескольких полей ввода, используя несколько приложений ng в HTML? - PullRequest
0 голосов
/ 15 февраля 2019
<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>

Вот мой код.Первое поле ввода работает отлично, но второе поле ввода не работает, даже если я использую начальную загрузку.Пожалуйста, кто-нибудь покажет мне правильный способ сделать это.Спасибо

Ответы [ 2 ]

0 голосов
/ 15 февраля 2019

Аджинкья указал вам правильное направление ... оттуда:

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>
0 голосов
/ 15 февраля 2019

На этот вопрос уже был ответ:

Самозагрузка для использования нескольких приложений ng

Пожалуйста, обратитесь и внесите соответствующие изменения в ваш код.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...