我有一个输入框,当向其中添加一些文本时,我希望将其存储在 ng-model 中
这就是我正在尝试做的事情,但不确定是否有效(使用 ng-change 指令):
<input class="form-control" type="text" ng-model="myCtrl.userAge" ng-change="checkAge()">
...在我的 Controller 中:
this.userAge;
this.checkAge = function() {
console.log(this.userAge);
}
最佳答案
myCtrl.checkAge() 而不仅仅是 checkAge()
此范围也会在函数内部发生变化,因此日志无法工作。
var ctrl = this;
ctrl.userAge;
ctrl.checkAge = function() {
console.log(ctrl.userAge);
}
关于javascript - Angular : entering text into an input box, 将其保存在 ng-model 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38256556/