[英]Angularjs assigning value to ng-model using ng-init
Hi I have following issue which seems easy and should work but is not. 嗨,我有以下问题似乎很简单,应该可以,但并非如此。
In my code I have input 在我的代码中,我输入了
<input type="text" ng-model="c.Id" ng-init="c.Id={{pId}}"/>
When I look at the DOM using firebug tool I see the value 当我使用Firebug工具查看DOM时,我看到了它的价值
<input type="text" ng-model="c.Id" ng-init="c.Id=6"/>
But it wont display 6 in the input box neither I can access it using #scope. 但是它不会在输入框中显示6,我也无法使用#scope访问它。 Please let me know what is wrong here and how to fix it so that ng-model can have from ng-init.
请让我知道这里出了什么问题以及如何解决它,以便ng-init可以使用ng-model。 Thanks
谢谢
ng-init
采用表达式,因此不需要花括号:
<input type="text" ng-model="c.Id" ng-init="c.Id=pId"/>
Assigning the value to ng-model using ng-value 使用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.