嗨我有以下问题,这似乎很容易,应该工作,但不是。
在我的代码中,我输入了
<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-model可以来自ng-init。 谢谢
答案 0 :(得分:20)
答案 1 :(得分:5)
ng-init
采用表达式,因此您不需要大括号:
<input type="text" ng-model="c.Id" ng-init="c.Id=pId"/>
答案 2 :(得分:2)
使用ng-value将值分配给ng-model
<input type="text" class="form-control" ng-model="inputPrice" />
<input type="text" ng-model="newPrice" ng-value="newPrice=inputPrice" />