sách gpt4 ăn đã đi

typescript - TypeError : self. parent.parent.parent.context 不是函数 Angular 2

In lại 作者:太空狗 更新时间:2023-10-29 17:50:40 28 4
mua khóa gpt4 giày nike

我创建了这个函数来保存我的taches

sauverTache(tache:Tache){

this.editionEnCours = true;
tache.estReelle = true;

this.sauverTache.emit(tache.id);
}

我这样在模板中调用我的函数


{{tache.typeTache}} 















我得到了这个错误

TypeError: self.parent.parent.parent.context.sauverTache is not a function

câu trả lời hay nhất

lấy事件发出的参数的方式只是通过关键字$sự kiện:

//(click)="edit=!edit; sauverTache(myTache);"
(click)="edit=!edit; sauverTache($event);"

如果你需要来自某个迭代数组的参数,你也可以传递它


...

*ngIf="edit" (click)="edit=!edit; sauverTache(myTache);">


...

如果我们需要组件类的一些设置,我们也可以

class MyComponent {
public myTache: number;
ngOnInit() {
this.myTache = 1;
}
}

现在我们可以要求像原始片段一样传递它

(click)="edit=!edit; sauverTache(myTache);

简单地说,我们要么需要让 myTache 成为一个局部变量(通常是 ngFor 的一部分),要么让我们的组件成为一个属性。如果我们需要使用事件参数——我们应该请求 $event

延长

最大的问题是在 sauverTache 内部,我们要在其中发出一些数据。这必须在 EventEmitter 的帮助下完成:

  sauverTacheObservable = new EventEmitter();

sauverTache(tache: Tache){

this.editionEnCours = true;
tache.estReelle = true;

// this is self calling.. and causing problem...
// this method does not have method emit
//this.sauverTache.emit(tache.id);

// but now, we call proper emitter
this.sauverTacheObservable.emit(tache.id);
console.log(tache.id);
}

a working plunker

关于typescript - TypeError : self. parent.parent.parent.context 不是函数 Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37614341/

28 4 0
太空狗
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress