Reputation: 99
I'm new to Angular and looking through the documentation but thought I'd also ask my question here.
I'm exporting a class which is getting large so I'd like to break it up into two files and store d1, d2, d3, etc in a separate file and import them where d1 is located below.
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";
} ...
What's the best way to do achieve this?
Upvotes: 0
Views: 316
Reputation: 129
The most simple and angular-unspecific approach for the original question would be to just make a file like string.ts:
export const d1 : string = "Hello World, this is a long string.";
and import the string via
import {d1} from './string';
Example: https://stackblitz.com/edit/angular-ayepho
Upvotes: 2