【发布时间】:2018-11-18 11:08:33
【问题描述】:
我正在使用ngx-formly,并尝试引入一个自定义模板,仅供查看。当模板是静态的时,还可以,但是如果我尝试引入一些角度操作,它就不起作用了。见this demo。有什么建议吗?
@Component({
selector: 'my-app',
template: `
<form [formGroup]="form" (ngSubmit)="submit(model)">
<formly-form [model]="model" [fields]="fields">
<button type="submit">Submit</button>
</formly-form>
</form>
{{ model|json }}
`,
})
export class AppComponent {
form = new FormGroup({});
model = {};
name = "John";
fields: FormlyFieldConfig[] = [
{template: `<div>{{name}}</div>`}, // <-- I expected to see John, but I saw {{name}}
{
key: 'name',
type: 'input',
templateOptions: {
label: 'Field 1',
placeholder: 'Formly is terrific!',
},
},
];
submit(model) {
console.log(model);
}
}
【问题讨论】:
-
使用 ngx-formly 有什么特别的原因吗?
-
@AjayOjha,我已经使用 ngx-formly 编写了一些代码。