2

我有一个表单,它的字段在组件内部。现在我想验证这些字段。问题是,我的消息不显示。该模式也没有任何影响。我试图在这篇文章的帮助下修复它,但没有成功。

有人知道如何显示我的消息吗?

索引.html

  <form name="dataForm">
    <md-tabs>
      <valid-data form-reference="dataForm"></valid-data>
    </md-tabs>

    <div>
      <md-button type="submit" ng-click="vm.save()"> Save </md-button>
    </div>
  </form>

组件.html

<md-tab label="Info Data">
  <md-content class="md-margin">

    <div layout-gt-sm="row">
      <md-input-container class="md-block" flex-gt-sm>
        <label>Name</label>
        <input ng-model="vm.data.name" name="name" required
               ng-minlength="10"
               ng-maxlength="20"
               pattern="{{validation.validateWord}}">
        <div ng-messages="formReference.name.$error" ng-if="formReference.name.$touched">
          <div ng-message="required">Name is required.</div>
          <div ng-message="minlength">minLength Error msg.</div>
          <div ng-message="maxlength">maxLength Error msg.</div>
          <div ng-message="pattern">Invalid characters.</div>
        </div>
      </md-input-container>
    </div>
  </md-content>
</md-tab>

这是模式

$rootScope.validation = {
    'validateWord': '^\\w+(-\\w+)*$', // 0-9, a-z, A-Z, underscores + dashes
  };

组件控制器.js

bindings: {
    formReference: '<'
  }
4

0 回答 0