我是 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";
} ...
实现这一目标的最佳方法是什么?
最佳答案
对于原始问题,最简单且与 Angular 无关的方法是只创建一个像 string.ts 这样的文件:
export const d1 : string = "Hello World, this is a long string.";
并通过导入字符串
import {d1} from './string';
关于javascript - Angular - 在当前 ts 文件中包含额外的 ts 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48429627/