[英]How to set combined value to ng-init
I want to assign ng-init value=d.id+d.concept_class like ng-init="m_concept_class= 12 abc " 我想分配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>
When i use this syntax ng-init="m_concept_class={{d.id}} {{d.concept_class}}"
i can see data "12 abc" in browser's inspect element feature, but does not display in text box. 当我使用这种语法
ng-init="m_concept_class={{d.id}} {{d.concept_class}}"
我可以在浏览器的检查元素功能中看到数据“ 12 abc”,但不会在文本框中显示。
You don't need to use interpolation, simply use concatenation. 您不需要使用插值,只需使用串联。
Use 采用
m_concept_class=d.id + ' ' +d.concept_class
Set value to input element while initializing it use ng-value
instead of ng-init
在初始化输入元素时使用
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>
Either you can also use ng-init
, but ng-value would be more preferable, its like value
attribute of html which will set value for input element and bind to the ng-model variable. 您也可以使用
ng-init
,但是ng-value更可取,它的html的like value
属性将为输入元素设置值并绑定到ng-model变量。
NOTE 注意
Don't use
{{}}
interpolation directive insideng-value
orng-init
as they only support expressions.请勿在
ng-value
或ng-init
使用{{}}
插值指令,因为它们仅支持表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.