Javascript 如何清除最后一个@Input变量值?角度2+
我使用changeDetection策略,它工作正常,但当我的组件被破坏时,当我回来时,我保存了最后一个值 示例I将3个值道具到子组件,并在我再次尝试道具数据时转到另一个组件,我看到了我的最后一个值 示例道具值1、2和3。 我看到了我最后的价值观。 如何去装饰它 检查代码和父组件:Javascript 如何清除最后一个@Input变量值?角度2+,javascript,html,css,angular,Javascript,Html,Css,Angular,我使用changeDetection策略,它工作正常,但当我的组件被破坏时,当我回来时,我保存了最后一个值 示例I将3个值道具到子组件,并在我再次尝试道具数据时转到另一个组件,我看到了我的最后一个值 示例道具值1、2和3。 我看到了我最后的价值观。 如何去装饰它 检查代码和父组件: <div class="row"> <app-poi-address [poiPin]="pinedAddress"></app-po
<div class="row">
<app-poi-address [poiPin]="pinedAddress"></app-poi-address>
</div>
this.pinedAddress = $event;
@Component({
changeDetection: ChangeDetectionStrategy.OnPush
})
export class PoiAddressComponent implements OnInit, OnChanges {
@Input () poiPin!: Object
public allPin: any[] = [];
constructor() { }
ngOnInit(): void {
console.log('datica' , this.poiPin);
}
ngOnChanges(): void {
console.log('HelloComponent: Change Detection count = ' , this.poiPin);
this.allPin.push(this.poiPin)
}
}
<div *ngFor="let d of allPin ">
<p> {{ d?.coords?.lat }} </p>
</div>
子组件:
<div class="row">
<app-poi-address [poiPin]="pinedAddress"></app-poi-address>
</div>
this.pinedAddress = $event;
@Component({
changeDetection: ChangeDetectionStrategy.OnPush
})
export class PoiAddressComponent implements OnInit, OnChanges {
@Input () poiPin!: Object
public allPin: any[] = [];
constructor() { }
ngOnInit(): void {
console.log('datica' , this.poiPin);
}
ngOnChanges(): void {
console.log('HelloComponent: Change Detection count = ' , this.poiPin);
this.allPin.push(this.poiPin)
}
}
<div *ngFor="let d of allPin ">
<p> {{ d?.coords?.lat }} </p>
</div>
保存最后的值。我想清除allPin的所有数组…这将在解构后重新创建组件时清除所有pin变量
ngOnInit(): void {
allPin = [];
console.log('datica' , this.poiPin);
}
你可以在Ngoninit中初始化它什么?我需要ngOnChange,因为我按下了单击项?我不明白你说什么?波波的父母也是吗?如果没有,父级保留pinedAddress的最后一个值,下次PoiAddressComponent再次创建最后一个pinedAddress传递给PoiAddressComponent时,您将获得最后一个值3。请不要破坏您的帖子。我需要它不要担心错误按钮,它应该是代码格式。谢谢