是否可以在angularjs中使用ng-model预填充表单?
Is it possible to prefill a form using ng-model in angularjs?
我有一个简单的表单
<form>
Name:
<input type="text" ng-model="edit"><br />
</form>
和控制器
中的一个简单数组$scope.statuses = [
{value: 1, text: 'status1'},
{value: 2, text: 'status2'},
{value: 3, text: 'status3'},
{value: 4, text: 'status4'}
];
我在视图中重复数组
<div ng-repeat="x in statuses">{{x.text}}<button ng-model="edit">edit</button></div>
所以我想知道当我点击编辑按钮可以使用ng-model在表单输入字段中填充数据吗?恰好
您可以通过在您的按钮中使用ng-click
而不是ng-model
来做到这一点。
你的按钮必须在点击时运行一个函数,就像这样:
<button ng-click="editFunction(x)">edit</button>
然后在控制器中,有一个函数:
$scope.editFunction = function(x){
$scope.edit = x.text;
}
在这个函数中,你将得到x的值,并在你的表格ng-model
中设置这个值。
有一个工作的活塞
相关文章:
- 从 Javascript 中设置 ng-model name
- Toggle Switch在包含ng model和ng repeat之后不进行切换
- 在Angularjs中,我如何使用ng repeat、ng model和ng click来动态更改内容
- 当与之关联的 ng-model 为 false 时,Angularjs 复选框值不会取消选中
- ng-model 绑定到选择标签生成的空默认值
- 对象不能在angularjs ng-model中访问
- 为什么 HTML 中的 Value 属性在与 AngularJS 中的 ng-model 一起使用时不起作用
- ng-repeat不绑定ng-model对象数组
- AngularJS:ng-model 绑定在使用 jQuery 更改时不会更新
- 选择/选项 ng-model 未绑定 ng-selected
- Angular ng-model 将数据作为数组发送到 rails-api
- 用ng重复填充表,并检查匹配的表头数据
- 为什么 AngularJS 在使用 ng-model 时不会在文本框上设置长度属性
- AngularJS:Ng:init-如何分配Ng:model
- AngularJS - 指令填充文本框,但ng-model没有值
- 使用 ng-model 的输入在通过 javascript 填充文本框时不绑定
- Angularjs -从输入文本ng-model填充json数组
- 如何使用javascript填充ng-model查询来过滤数据
- 是否可以在angularjs中使用ng-model预填充表单?
- 用一个属性预填充输入,但将ng-model设置为不同的属性