Angular ng-Model 第二次没有出现

Angular ng-Model not showing up second time

我在特定情况下显示的模态弹出窗口中包含此代码,第一次显示模态时一切正常。

我有这个代码:

<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 -> 最后一段