gpt4 book ai didi

javascript - Angular ng-模型第二次没有出现

转载 作者:行者123 更新时间:2023-12-03 05:12:03 24 4
gpt4 key购买 nike

我在模式弹出窗口中包含此代码,该代码在某些情况下显示,第一次显示模式时一切正常。

我有这个代码:

<div class="form-group">
<p>First Name:</p>
{{vm.user.name_first}}
<input type="text" class="form-control" ng-model="vm.user.name_first" name="firstName" required />
</div>

关闭模态框并再次打开后, p 下面的文本显示正确,但是 ng-model (在 p 之后具有相同的内容),显示输入为空而不是 vm.user.name_first 的内容.

发生什么事情只会影响第二次?

最佳答案

试试这个:

<div class="form-group">
<p>First Name:</p>
{{vm.user.name_first}}
<input type="text" class="form-control" ng-model="vm.user.name_first" name="firstName" ng-model-options="{ getterSetter: true }" required />

说明:

Sometimes it's helpful to bind ngModel to a getter/setter function. A getter/setter is a function that returns a representation of the model when called with zero arguments, and sets the internal state of a model when called with an argument. It's sometimes useful to use this for models that have an internal representation that's different from what the model exposes to the view.

https://docs.angularjs.org/api/ng/directive/ngModel ->最后一段

关于javascript - Angular ng-模型第二次没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41766114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com