我有一个表单,其字段在组件内。现在我想验证字段。问题是,我的消息没有显示出来。这种模式也没有任何影响。我试图在post的帮助下修复它,但没有成功。
有人知道我该如何显示我的信息?
的index.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>
component.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
};
component.controller.js
bindings: {
formReference: '<'
}