【问题标题】:Angular formly templateOptions description not showingAngular formly templateOptions 描述未显示
【发布时间】:2019-08-07 15:30:41
【问题描述】:

我尝试在我的正式字段上显示描述,但它没有出现。

我尝试在架构和运行时包含描述,但在任何一种情况下,它都不会出现。

Schema.json:

{
    "key": "CommentText",
    "type": "input",
    "className": "form-group",
    "templateOptions": {
        "label": "Comment text",
        "required": true,
        "maxLength": 1000,
        "description": "test"
    }
}

目的是显示具有 maxlength 属性的字段的字符倒计时。但首先我需要显示一个基本描述。

【问题讨论】:

    标签: angular angular-formly


    【解决方案1】:

    最小/最大长度应由验证器完成。

     validators: [
     ],
      validationMessages: [
        { name: MaxLengthValidator.validatorName, message: MaxLengthValidator.message },
      ],
    

    但在我的代码中,我在模板中创建了带有描述的自定义输入:

    <input class="formly-string-input"
           type="text"
           [formControl]="formControl"
           [formlyAttributes]="field"/>
    <span *ngIf="field.templateOptions.description" class="form-control-info">{{field.templateOptions.description}}</span>
    

    而且我认为 ngx-formly 输入没有要显示的描述

    Sourece code of input

    
    import { Component } from '@angular/core';
    import { FieldType } from '@ngx-formly/core';
    
    @Component({
      selector: 'formly-field-input',
      template: `
        <input *ngIf="type !== 'number' else numberTmp" [type]="type" [formControl]="formControl" class="form-control" [formlyAttributes]="field" [class.is-invalid]="showError">
        <ng-template #numberTmp>
          <input type="number" [formControl]="formControl" class="form-control" [formlyAttributes]="field" [class.is-invalid]="showError">
        </ng-template>
      `,
    })
    export class FormlyFieldInput extends FieldType {
      get type() {
        return this.to.type || 'text';
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      • 2018-12-05
      • 1970-01-01
      • 2022-12-30
      • 2020-02-06
      相关资源
      最近更新 更多