在输入字段中自定义验证以获取唯一值

时间:2018-12-07 12:10:15

标签: angularjs angularjs-validation

我必须将AngularJS 1.7用于具有表单的项目,并且必须验证所需的输入字段,具有特定的模式并具有唯一的值。为此,我正在这样做:

  input#item-name(
    name="name",
    type="text",
    required,
    ng-pattern="$ctrl.pattern.id",
    ng-model="$ctrl.item.name",
  )

  div(ng-messages="addItemForm.name.$error")
    div(ng-messages-include="error-messages")

我已经介绍了必需的和模式一。但无法包含唯一验证。

我有一个包含所有现有值的数组:

this.existingItems = ['A','B','C];

我已经尝试过类似的操作,但是没有用:

 input#item-name(
    name="name",
    type="text",
    required,
    ng-pattern="$ctrl.pattern.id",
    ng-model="$ctrl.item.name",
    ng-unique="$ctrl.existingItems",
  )

  div(ng-messages="addItemForm.name.$error")
    div(ng-messages-include="error-messages")

我已经在组件内部使用了这部分代码,并将“ this”指向“ $ ctrl”。

0 个答案:

没有答案
相关问题