Angular 角度是否会破坏组件';离开后有什么财产?

Angular 角度是否会破坏组件';离开后有什么财产?,angular,Angular,根据此部件代码: @Component({ selector: "app-create-plan", templateUrl: "./create.html", styleUrls: ["../calendar-thematic-plan-create.component.css"] }) export class CreatePlanComponent extends CalendarThematicPlanCreateComponent implements OnDestro

根据此部件代码:

@Component({
  selector: "app-create-plan",
  templateUrl: "./create.html",
  styleUrls: ["../calendar-thematic-plan-create.component.css"]
})
export class CreatePlanComponent extends CalendarThematicPlanCreateComponent
  implements OnDestroy {
  public rows: any[] =[];
  constructor() {}
Angular是否破坏组件的属性,如
公共行:any[]=[]离开组件后?或者我必须自己在恩格德斯特罗做这件事

  ngOnDestroy(): void {
    this.rows = [];
  }

这取决于,如果组件真的被破坏了,那么其中的所有属性都被破坏了。请注意,如果您正在使用路由,请执行以下操作:

{path: ':id', component: someRandomComponent }

如果只有url中的id发生更改,Angular将重新使用组件。在这种情况下,您必须注意组件中的属性,因为它们没有重新初始化。

这取决于,如果组件确实被销毁,那么其中的所有属性都将被销毁。请注意,如果您正在使用路由,请执行以下操作:

{path: ':id', component: someRandomComponent }

如果只有url中的id发生更改,Angular将重用该组件,在这种情况下,您必须注意组件中的属性,因为它们没有重新初始化。

好的,那么为什么我在析构函数中看到数据:`ngondstroy():void{console.log(this.rows);}`我可以确保this.rows在离开组件后为空吗?在销毁之前调用ngondstroy。因此,如果您在其中记录任何数据,您将看到它的实际值(因为组件还没有实际销毁…)请查看此处的Ngondestory事件挂钩以了解更多信息:Angular销毁指令/组件之前的清理。取消订阅可观察对象并分离事件处理程序以避免内存泄漏。就在Angular销毁指令/component.Okay之前调用。那么为什么我会在析构函数中看到数据:`ngondstroy():void{console.log(this.rows);}`我可以确保this.rows在离开组件后为空吗?ngondstroy在销毁之前调用。因此,如果您在其中记录任何数据,您将看到它的实际值(因为组件还没有实际销毁…)请查看此处的Ngondestory事件挂钩以了解更多信息:Angular销毁指令/组件之前的清理。取消订阅可观察对象并分离事件处理程序以避免内存泄漏。在Angular销毁指令/组件之前调用。