Angularjs 角度形式-不显示错误消息

Angularjs 角度形式-不显示错误消息,angularjs,angular-formly,Angularjs,Angular Formly,下面是我所在领域的一个简单示例: { key: 'name', type: 'input', validators: { nameValid: { expression: function(viewValue, modelValue){ var value = modelValue || viewValue; return (some condition on value); }, message: '$vi

下面是我所在领域的一个简单示例:

{
  key: 'name',
  type: 'input',
  validators: {
    nameValid: {
      expression: function(viewValue, modelValue){
        var value = modelValue || viewValue;
        return (some condition on value);
      },
      message: '$viewValue + " is not a valid string"'
    }
  },
  templateOptions: {
    label: 'Name',
    placeholder: 'Name',
    options: [],
    required: true
  },
  validation: {
    messages: {
      required: function(viewValue, modelValue, scope) {
        return scope.to.label + ' is required';
      }
    }
  }
},

我为特定条件和所需字段条件设置了验证消息。但是,如果不满足我的条件或未填写字段,则不会显示任何错误消息。该字段只会变为红色(应该如此),但我如何才能让它也显示我的错误消息呢?

添加错误模板,然后重试,最好提供一个用于调试的jsbin链接

<script type="text/ng-template" id="custom-messages.html">
    <div class="my-messages" ng-messages="options.formControl.$error" ng-if="options.validation.errorExistsAndShouldBeVisible">
        <div class="error-message" ng-message="{{::name}}" ng-repeat="(name, message) in ::options.validation.messages">
            {{message(options.formControl.$viewValue, options.formControl.$modelValue, this)}}
        </div>
    </div>
</script>

{{消息(options.formControl.$viewValue,options.formControl.$modelValue,this)}

您可以在app.config函数中设置wrapper to input字段以显示错误消息

app.config(function (formlyConfigProvider)({
      formlyConfigProvider.setWrapper({
         name: 'validation',
         types: ['input'],
         template:'<formly-transclude></formly-transclude><div ng-messages="fc.$error" ng-if="form.$submitted || options.formControl.$touched" class="error-messages"><div ng-message="{{ ::name }}" ng-repeat="(name, message) in ::options.validation.messages" class="message">{{ message(fc.$viewValue, fc.$modelValue, this)}}</div></div>'
        //templateUrl: 'error-messages.html'
});}};
app.config(函数(formlyConfigProvider)({
formlyConfigProvider.setWrapper({
名称:“验证”,
类型:[“输入”],
模板:“{message(fc.$viewValue,fc.$modelValue,this)}”
//templateUrl:'error messages.html'
});}};

谢谢,我好像丢失了一个错误模板。你能告诉我(也许是一行一行)这是怎么回事吗?你可以选择angular formly页面上给出的任何示例。如果你感兴趣,它会显示错误消息和错误摘要