typescript:调用类析构函数从数组中删除对象
只是想知道些什么。 我发现自己处于这种情况:typescript:调用类析构函数从数组中删除对象,typescript,ionic-framework,Typescript,Ionic Framework,只是想知道些什么。 我发现自己处于这种情况: export class Legs { legs: Leg[]; constructor(private modalCtrl:ModalController) { this.legs = [] } addLeg(){ this.legs.push(new Leg(this.modalCtrl));//Leg is a component rendered in a ngcontainer thru ngfor
export class Legs {
legs: Leg[];
constructor(private modalCtrl:ModalController) {
this.legs = []
}
addLeg(){
this.legs.push(new Leg(this.modalCtrl));//Leg is a component rendered in a ngcontainer thru ngfor
}
removeLeg(i){
this.legs.splice(i,1)
}
}
有没有一种方法可以替代removeLeg()函数,从对象Leg(在AddLeg中创建)的内部调用它
我可以想象腿部html文件中的一个按钮调用析构函数。。
这样行吗?它会破坏对象并将其从数组Legs中删除吗?您需要一个Leg到实际类(Legs)的引用 下一步,你可以从腿部打电话,比如:
legs.removeLeg(i)
或
legs.removeLeg(i)
legs.legs.splice(i,1)