我有一个字段身份证在$ scope.data项目,名与功放的集合; 年龄,被显示在用NG-重复指令的观点。对于每一组的项目,有一个相应的编辑按钮。
I have a collection of items in $scope.data with fields "id","name" & "age", that are being displayed in the view using ng-repeat directive. For each set of items, there is a corresponding "edit button".
我希望能够访问值的特定集合为其编辑按钮是pressed项目。
I want to be able to access values for the particular set of items for which edit button was pressed.
HTML:
<div ng-controller="Ctrl">
<div ng-repeat="i in data">
Name: {{i.name}}
Age: {{i.age}}
<form ng-submit="submit()">
<input type="text" ng-model="i.id"/>
<input type="submit" value="Edit" />
</form>
</div>
</div>
脚本:
function Ctrl($scope)
{
$scope.data = [
{id:1,name:"Alex",age:22},
{id:2,name:"Sam", age:28}
];
$scope.submit = function() {
//access id of user for which edit was clicked
};
}
什么是做到这一点的正确方法?
What is the right way to do this?
试试这个:
HTML
<form ng-submit="submit(i.id)">
JavaScript的:
JavaScript:
$scope.addBrandModelFilter = function(useId) {
// you have userId
};