我想在我的 Formly 表单中包含一个简单的链接,例如
<a href="https://google.com">Search</a>
但是我找不到如何扩展a
html 元素
我的自定义 Formly 组件是
import { Component } from '@angular/core';
import { FieldType } from '@ngx-formly/core';
@Component({
selector: 'formly-link-component',
template: `
<a [href]="to.url">{{ to.title }}</a>
`,
})
export class FormlyLinkComponent extends FieldType {
}
我已将自定义组件添加为 app.module.ts 中的类型
{ name: "link", component: FormlyLinkComponent },
而表单配置 JSON 是
{
"schema": {
"title": "A registration form",
"description": "A simple form example.",
"type": "object",
"required": [
"firstName",
"lastName"
],
"properties": {
"webLink": {
"type": "link",
"url": "https:\/\/en.wikipedia.org\/wiki\/Chuck_Norris",
"title": "Click Me"
},
"firstName": {
"type": "string",
"title": "First name",
"default": "Chuck"
},
"lastName": {
"type": "string",
"title": "Last name"
},
"age": {
"type": "string",
"title": "Age"
},
"bio": {
"type": "string",
"title": "Bio"
},
"password": {
"type": "string",
"title": "Password",
"minLength": 3
},
"telephone": {
"type": "string",
"title": "Telephone",
"minLength": 10
}
}
},
"model": {
"lastName": "Norris",
"age": 75,
"bio": "Roundhouse kicking asses since 1940",
"password": "noneed"
}
}
Stackblitz 在这里 https://stackblitz.com/edit/ngx-formly-ui-material-fv4a2x?file=src/assets/simple.json