[英]How to resize the text area value dynamically using Angular.js
我需要一個幫助。我需要使用Angular.js動態設置文本區域值。 我在下面解釋我的代碼。
<textarea id="spec" name="address" class="form-control" placeholder="Add Address" rows="4" style="height:73px" ng-model="address" readonly="readonly" ></textarea>
在上面的文本區域中,我需要設置以下值。
var address="USA";
var city="city1";
var pin="7521098"
上面的值應顯示在文本區域內,如下所示。
address:USA.
City:city1.
Pin:7521098
您根本沒有使用雙向數據綁定。
您需要的是
$scope.address = "USA";
在您的控制器中。 然后,變量將綁定到您的文本區域。 但是您想在文本區域內顯示整個屬性。 然后,您必須執行以下操作:
$scope.textareaContent = address + city + pin;
在您的HTML中
ngmodel="textareaContent"
//更新
$scope.textareaContent = 'adress:' + address + '<br/>city:' + city + '<br/>pin:' + pin;
你可以試試這個
在控制器中,您可以基於值變量設置文本區域的值
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> </script>
<script>
var app=angular.module("app",[]);
app.controller("app_controller",function($scope){
var address="USA";
var city="city1";
var pin="7521098"
var address2="Address:"+address+"\n City:"+city+"\nPin:"+pin;
$scope.address1=address2;
});
</script>
<body ng-app="app">
<div ng-controller="app_controller">
<textarea id="spec" name="address" placeholder="Add Address" rows="4" style="height:73px" ng-model="address1" ></textarea>
</div>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.