Angularjs价值分配使用NG-INIT到NG-模型 [英] Angularjs assigning value to ng-model using ng-init
本文介绍了Angularjs价值分配使用NG-INIT到NG-模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我有以下问题,它似乎很容易,应该工作,但并非如此。
Hi I have following issue which seems easy and should work but is not.
在我的code我输入
<input type="text" ng-model="c.Id" ng-init="c.Id={{pId}}"/>
当我使用Firebug工具来看DOM我看到价值
When I look at the DOM using firebug tool I see the value
<input type="text" ng-model="c.Id" ng-init="c.Id=6"/>
但是,在输入框中显示习惯既不6我可以用#scope访问它。
请让我知道什么是错在这里,以及如何解决它,这样NG模型可以从NG-INIT有。
谢谢
But it wont display 6 in the input box neither I can access it using #scope. Please let me know what is wrong here and how to fix it so that ng-model can have from ng-init. Thanks
推荐答案
得到除权pression摆脱牙套,使其从范围直接评价PID
Get rid of the braces in the expression so that it will evaluate pId directly from the scope
<input type="text" ng-model="c.Id" ng-init="c.Id=pId"/>
这篇关于Angularjs价值分配使用NG-INIT到NG-模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文