我用选择模板创建了一个指令,但我需要“名称”标签,所以我可以进行验证,但我不知道如何添加它。我尝试添加 attr 但它没有用。
<form name="newForm" ng-submit="save()">
<div>
Name: <input required ng-model="newSupplier.Name" name="myName" type="text" required/>
<span ng-show="newForm.myName.$error.required">*</span>
<br />
Status: <keywords name="myStatus" title="Choose Status" label="" array="myKeyword" keyword-type="ActivityType" supplier-id="newSupplier.Id" opt-value="Id" opt-description="Description"></keywords>
<span ng-show="newForm.myStatus.$error.required">*</span>
<br>
<button type="submit">Save</button>
<br /><i>How to save the ID of the selected dropdown?</i>
</div>
</form>
JS
app.directive('keywords', function(){
return {
restrict: 'E',
scope: {
array: '=',
supplierId : '='
},
template: '<label>{{label}}</label>' +
'<select ng-model="supplierId" ng-options="a[optValue] as a[optDescription] for a in array | filter: keywordType">' +
'<option style="display: none" value="">-- {{title}} --</option>' +
'</select>',
link: function (scope, element, attrs) {
scope.label = attrs.label;
scope.title = attrs.title;
scope.optValue = attrs.optValue;
scope.optDescription = attrs.optDescription;
scope.keywordType = attrs.keywordType;
}
};
});