本文介绍了angularjs传递参数通过指令和NG重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们再试一次:
这里的工作plunker:
Another forked plunker: http://plnkr.co/edit/mdKBoEffoUo2ilH7Jd3L?p=preview
$scope.getModels = function(items) {
var params = {};
if (angular.isArray(items)) {
for (var i = 0; i < items.length; i++) {
var item = items[i];
if(angular.isArray(item.fields)) {
for (var j = 0; j < item.fields.length; j++) {
var field = item.fields[j];
params[field.id] = field.model;
}
}
}
}
alert(JSON.stringify(params, '', 4));
};
由于动态输入名称尚未这里尚未实施(进行验证。而且因为如此,我认为你必须要管理形式使用submittion自己 ngModel
。
在这里检查分叉〔实施例:
Check the forked exmaple here: http://plnkr.co/edit/8cP5YMKUGu6LfBCsRxAZ?p=preview
模板:
<div class="form-group" ng-form="form" ng-class="{true: 'has-error', false: 'has-success'}[form.fieldName.$invalid]">
<label class="control-label col-sm-2" for="fieldName">{{fieldLabel}}</label>
<div class="col-sm-6">
<input class="form-control" type="{{fieldType}}" placeholder="enter valid name" name="fieldName" ng-model="fieldModel" ng-minlength=3 ng-maxlength=20 required/>
<span class="help-block">
<span ng-show="form.fieldName.$error.required">Required field</span>
<span ng-show="form.fieldName.$error.minlength">Too few chars - min is (6)</span>
<span ng-show="form.fieldName.$error.maxlength">Too much chars - max is (20)</span>
</span>
</div>
</div>
HTML
<form-field ng-repeat="field in tabItem.fields" ng-model='field.model'
field-type="field.type" field-name='field.id' field-label='field.label'>
</form-field>
JS:
KPNDirectives.directive("formField", function () {
return {
restrict: 'E',
scope: {
fieldModel: '=ngModel',
fieldType: '=',
fieldLabel: '=',
fieldName: '='
},
templateUrl: 'formField.html'
};
});
这篇关于angularjs传递参数通过指令和NG重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!