Javascript 无法读取属性';价值';在Object.onClick处为null的角度
我想在视图中查看上传的文件按钮,但单击视图按钮时,错误显示为 无法读取null的属性“value” at Object.onClick .component.tsJavascript 无法读取属性';价值';在Object.onClick处为null的角度,javascript,angular,typescript,button,file-upload,Javascript,Angular,Typescript,Button,File Upload,我想在视图中查看上传的文件按钮,但单击视图按钮时,错误显示为 无法读取null的属性“value” at Object.onClick .component.ts export class OnboardingProcessComponent implements OnInit { //some code.. measureDetailsForm = new FormGroup({}); measureDetailsModel: any = {}; measureDetailsOpt
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')
}
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);
}
}
}
我使用了formly,因此我单独创建了按钮组件,用于创建按钮,如
按钮类型.组件.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')
}
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);
}
}
}
从'@angular/core'导入{Component};
从'@ngx formly/core'导入{FieldType};
@组成部分({
选择器:“表单字段按钮”,
模板:`
{{to.text}}
`,
})
导出类FormlyFieldButton扩展FieldType{
onClick($event){
if(this.to.onClick){
this.to.onClick($event);
}
}
}
Hello StackOverFlow。代码中存在多个语法错误,是否尝试编辑代码?