当我点击按钮时,我应该发送到数据层信息,但我不知道该怎么做,因为我使用的是 Angular 6,所以我需要使用 Typescript 和 window.dataLayer.push 不起作用并给我这个错误
形式
<form>
<div class="radio">
<input value="Yes" id="radio-1" [(ngModel)]="answer" name="radio" type="radio">
<label class="radio-label rob-l" for="radio-1">Yes</label>
</div>
<div class="radio">
<input value="No" id="radio-2" [(ngModel)]="answer" name="radio" type="radio">
<label class="radio-label rob-l" for="radio-2">No</label>
</div>
</div>
<div class="btn">
<button (click)="Next()" type="submit">Next question</button>
</div>
</form>
我想收到这样的东西
Next(){
if ((this.path == 1) && (this.answer === "Yes" || this.answer === "No"))
{
// window.dataLayer = window.dataLayer || [];
// window.dataLayer.push({
// 'event': 'answer',
// 'answer': this.answer
// });
this.path++;
this.answer = "";
}
}
使用此代码解决的问题:
window['dataLayer'] = window['dataLayer'] || [];
window['dataLayer'].push({
'event': 'Answer',
'failedText': this.answer
});
ngOnInit() {
window['dataLayer'] = window['dataLayer'] || {};
}