【发布时间】:2021-09-15 16:01:51
【问题描述】:
我真的无法理解,我已经尝试在谷歌搜索,这里,任何地方......我不明白为什么这个错误仍然显示。
我有这样的事情:
parent.html
<child-1 [(type)]="type"></child-1>
parent.ts
type = 0;
getTypeToOtherthings() { // function to use in a mouse event, it's not important for that
console.log(type);
}
child-1.html
<child-2 [(type)]="type">
child-1.ts // 这个组件就像是 parent 和 child-2 之间的桥梁(可能问题出在这里,我真的不知道)
_type: number;
@Input() set type(val: number) {
this.typeChange.emit(val);
this._type= val;
}
get type() {
return this._type;
}
@Output() typeChange: EventEmitter<number> = new EventEmitter<number>();
child-2.html
(一些 HTML)
child-2.ts
_type: number;
@Input() set type(val: number) {
this.typeChange.emit(val);
this._type= val;
}
get type() {
return this._type;
}
@Output() typeChange: EventEmitter<number> = new EventEmitter<number>();
/*I need change Type variable in childs-2, so i put this in
onInit (but i already tryed put this in all Afters... , using Promise, ChangeDetectorRef, nothing works,
like everything works fine but the error still)*/
ngOnInit() {
this.type = 2;
}
毕竟我几乎要放弃了
【问题讨论】:
-
您实际上并没有发布错误消息,第一行可能就足够了。并且在从parent传到child 1和从child 1传到child 2时临时重命名type,这样调试就更容易了。
标签: angular typescript