![](/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.