0

我想使用 tailwind 来做我所有的样式,并且不想在我的代码中添加额外的库。

这是我想出的一个简单示例:

https://stackblitz.com/edit/angular-ivy-uxrxrc?file=src%2Fapp%2Fformly-component%2Fformly-component.ts

我所做的:
创建了一个简单的组件,里面有一个基本的输入字段。Angular 似乎编译得很好,但 formly 似乎没有显示任何字段。它与Error: [Formly Error] There is no type by the name of "input".

我似乎也无法在没有主题的文档中找到任何示例。

4

1 回答 1

0

正式提供一组开箱即用的主题,例如材料,引导程序..但这不会阻止您创建自己的主题,唯一需要的步骤是定义自定义字段类型,如https://formly.dev/guide中所述/custom-formly-field 在这里总结的步骤是:

  1. 使用 name创建自定义字段类型input
import { Component } from '@angular/core';
import { FieldType } from '@ngx-formly/core';

@Component({
 selector: 'formly-datetimepicker',
 template: `
   <input [formControl]="formControl"></input>
 `,
})
export class InputFieldType extends FieldType {}
  1. NgModule通过声明定义您的字段类型:
@NgModule({
 declarations: [InputFieldType],
 imports: [
   ....
   FormlyModule.forRoot({
     types: [
       { name: 'input', component: InputFieldType },
     ],
   }),
 ],
})
export class AppModule {}
  1. type在您的字段配置中设置类型:
fields = [
  {
    key: 'name',
    type: 'input',
  },
]

仍然困惑检查 Formly UI 源代码https://github.com/ngx-formly/ngx-formly/tree/master/src/ui

于 2020-05-15T23:33:59.960 回答