我正在根据SDK在Angular组件中嵌入Typeform。
组件模板具有div:
<div
#embedTypeform
style="width: 100%; height: 500px;"
></div>
我在AfterViewInit中使用SDK:
import { Component,ElementRef,ViewChild,AfterViewInit } from '@angular/core';
import * as typeformEmbed from '@typeform/embed';
@Component({
selector: 'app-answer-form',templateUrl: './answer-form.component.html',styleUrls: ['./answer-form.component.css']
})
export class AnswerFormComponent implements AfterViewInit {
@ViewChild('embedTypeform',{ static: false }) embedElement: ElementRef;
ngAfterViewInit() {
if (this.embedElement) {
console.log(this.embedElement);
typeformEmbed.makeWidget(
this.embedElement,'https://xxx.typeform.com/to/xxx',{
hideHeaders: true,hideFooter: true,opacity: 75,buttonText: 'Take the survey!',onSubmit: () => {
console.log('Typeform successfully submitted');
}
}
);
}
}
}
实际上我得到了
TypeError: Cannot read property 'length' of undefined
有什么想法吗?