[英]How to set combined value to ng-init
我想分配ng-init value = d.id + d.concept_class像ng-init =“ m_concept_class = 12 abc ”
<div ng-repeat="d in data">
<input type="text" ng-model="m_concept_class"
ng-init="m_concept_class={{d.id; d.concept_class}}" >
</div>
當我使用這種語法ng-init="m_concept_class={{d.id}} {{d.concept_class}}"
我可以在瀏覽器的檢查元素功能中看到數據“ 12 abc”,但不會在文本框中顯示。
您不需要使用插值,只需使用串聯。
采用
m_concept_class=d.id + ' ' +d.concept_class
您可以簡單地添加它:-)
<div ng-repeat="d in data">
<input type="text" ng-model="m_concept_class"
ng-init="m_concept_class=d.id +d.concept_class" />
</div>
在初始化輸入元素時使用ng-value
而不是ng-init
設置值
<div ng-repeat="d in data">
<input type="text" ng-model="m_concept_class" ng-value="m_concept_class=d.id +' '+ d.concept_class" >
</div>
您也可以使用ng-init
,但是ng-value更可取,它的html的like value
屬性將為輸入元素設置值並綁定到ng-model變量。
注意
請勿在
ng-value
或ng-init
使用{{}}
插值指令,因為它們僅支持表達式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.