簡體   English   中英

是否可以選擇不正式使用主題?

[英]Is there an option to NOT use a theme in formly?

我想使用 tailwind 來做我所有的樣式,並且不想在我的代碼中添加額外的庫。

這是我想出的一個簡單示例:

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

我做了什么:
創建了一個簡單的組件,其中包含一個基本的輸入字段。 Angular 似乎編譯得很好,但形式似乎沒有顯示任何字段。 它出現錯誤並出現Error: [Formly Error] There is no type by the name of "input"

我似乎也無法在沒有主題的文檔中找到任何示例。

正式提供一組開箱即用的主題,例如引導程序..但這並不妨礙您創建自己的主題,唯一需要的步驟是定義自定義字段類型,如https://formly.dev/guide中所述/custom-formly-field在這里總結的步驟是:

  1. 使用名稱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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM