本文介绍了将值绑定到 Angular JS 中的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的输入
<input type="text" name="widget.title" ng-model="widget.title" value="{{widget.title}}"/>
我想动态更改输入值,所以我使用它,但它不会更改值:
I want to change input value dynamically so i use that but it doesn't change the value:
$scope.widget.title = 'a';
推荐答案
您根本不需要设置该值.ng-model 负责这一切:
You don't need to set the value at all. ng-model takes care of it all:
- 设置模型的输入值
- 更改输入时更新模型值
- 当您从 js 更改模型时更新输入值
这里是小提琴:http://jsfiddle.net/terebentina/9mFpp/
这篇关于将值绑定到 Angular JS 中的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!