首页 > 解决方案 > Angular 6 组件类拆分文件

问题描述

如何将一个组件类拆分为多个文件?

想象一下这个组件:

//main.ts
@Component({
  selector: "sg-page-main",
  templateUrl: "main.html",
})

export class MainPageComponent {
 public b : number = 41;

  public aff(): void {console.log(this.b)}
  public increment(): void {this.b=this.b+1}
}

我想将函数“增量”放入另一个文件中。在我的项目中,组件中有 50 多个函数,它们都使用“this”范围。

标签: angularcomponents

解决方案


推荐阅读