2015-03-25 61 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因爲它們只 表示支持。