2015-03-25 64 views
0

我要分配NG-INIT值= d.id + d.concept_class像NG-INIT = “m_concept_class = 12 ABC如何设置组合值到NG-INIT

<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”,但不显示在文本框中。

回答

1

您不需要使用插值,只需使用串接。

使用

m_concept_class=d.id + ' ' +d.concept_class 
1

你可以简单地:-)

<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> 

Fiddle

0

设定值将它添加到输入元素,同时初始化它使用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的value属性,它将为input元素设置值并绑定到ng-model变量。

注意

不要使用内部ng-value{{}}插补指令或ng-init因为它们只 表示支持。