簡體   English   中英

使用ID更新Textarea值,而不是在AngularJs中使用ng-model

[英]Update Textarea value with ID instead of using ng-model in AngularJs

我可以使用以下代碼片段同時更新一個文本區域的值

<div ng-app="myApp">
     <div ng-controller="myCtrl">
       <input id="id1" type="text">

       <input id="id2" type="text">
     </div>
   </div>

Script file:

var myApp = angular.module('myApp', []);

  myApp.controller('myCtrl', ['$scope', function($scope){

    $scope.text1 = '';

  }]);

有沒有一種方法可以使用ID而不是ng-model屬性來同時更新值。 謝謝!!!

您可以嘗試使用$watch

$scope.$watch('text1', function () {
    document.getElementById('id2').value = $scope.text1;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM