我想在查看按钮中查看上传的文件,但是当单击查看按钮时,错误显示为
无法读取 null 的属性“值” 在 Object.onClick
.component.ts
export class OnboardingProcessComponent implements OnInit {
//some code..
measureDetailsForm = new FormGroup({});
measureDetailsModel: any = {};
measureDetailsOptions: FormlyFormOptions = {};
{
className:'flex-1',
type: 'onboarding-file',
key: 'PAS_20350_Certificate',
templateOptions: {
label: 'PAS 2030',
change: (field, $event)=> {
console.log($event);
console.log(field);
}
},
},
{
type: 'button',
templateOptions: {
//label: 'PAS 2030',
text: 'VIEW',
onClick: ($event) => {
// this.form.get('someInput').setValue('clicked!');
this.openFile(this.measureDetailsForm.get('PAS_20350_Certificate').value)
},
},
},
ngOnInit(): void {
}
openFile(fileUrl){
window.open(fileUrl, '_blank')
}
我使用了formly,所以我单独创建了按钮组件来创建按钮...
button-type.component.ts
import { Component } from '@angular/core';
import { FieldType } from '@ngx-formly/core';
@Component({
selector: 'formly-field-button',
template: `
<div>
<button [type]="to.type" class="lg-blue-button" (click)="onClick($event)">
{{ to.text }}
</button>
</div>
`,
})
export class FormlyFieldButton extends FieldType {
onClick($event) {
if (this.to.onClick) {
this.to.onClick($event);
}
}
}