![](/img/trans.png)
[英]AngularJS text input with ng-model but needs default value not working with value= or ng-init=
[英]Angularjs assigning value to ng-model using ng-init
嗨,我有以下問題似乎很簡單,應該可以,但並非如此。
在我的代碼中,我輸入了
<input type="text" ng-model="c.Id" ng-init="c.Id={{pId}}"/>
當我使用Firebug工具查看DOM時,我看到了它的價值
<input type="text" ng-model="c.Id" ng-init="c.Id=6"/>
但是它不會在輸入框中顯示6,我也無法使用#scope訪問它。 請讓我知道這里出了什么問題以及如何解決它,以便ng-init可以使用ng-model。 謝謝
ng-init
采用表達式,因此不需要花括號:
<input type="text" ng-model="c.Id" ng-init="c.Id=pId"/>
使用ng-value將值分配給ng-model
<input type="text" class="form-control" ng-model="inputPrice" />
<input type="text" ng-model="newPrice" ng-value="newPrice=inputPrice" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.