Angular - 在当前ts文件中包含额外的ts文件

时间:2018-01-24 18:48:37

标签: javascript angular typescript include export

我是Angular的新手并查看文档,但我想我也会在这里提出我的问题。

我正在导出一个越来越大的类,所以我想把它分成两个文件并将d1,d2,d3等存储在一个单独的文件中,然后将它们导入到d1位于下面的位置。

  export class HomeComponent implements OnInit {

  name: string;
  AppModule;
  d1: string = " lengthy string of text";
  d2: string = " another lengthy string of text";
  d3: string = " another lengthy string of text";
  // goes on for many lines

  constructor() { }

  ngOnInit() {
  this.name = "Home";
  } ...

实现这一目标的最佳方法是什么?

1 个答案:

答案 0 :(得分:2)

对于原始问题,最简单和有角度的非特定方法是创建一个类似string.ts的文件:

http://www.url.com/[^/]+/?.{0}

并通过

导入字符串
export const d1 : string = "Hello World, this is a long string.";

示例:https://stackblitz.com/edit/angular-ayepho

相关问题