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

标签 javascript angularjs angular-ngmodel

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

我有这个代码:

<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/

相关文章:

angularjs - Angular 选择显示空 ng-model 值的默认值

javascript - jshint 理解 Angular 吗?

javascript - 动态行的内联计算

javascript - 在nodejs、express和angular1.x中动态上传指定路径的所有文件

angularjs - Angular-UI Bootstrap typeahead ngmodel 在放置在选项卡内时无法按预期工作

javascript - Angular : ng-model directive not working with `<span>` element

javascript - Electron 应用程序在需要 SQLITE3 时出现异常

java - 如何自动选中所有具有不同名称和不同值的复选框?

javascript - 父子 Controller 的 Angular JS 错误

javascript - 在选择中为 ng-model 分配一个对象