例です。
まず下記のようなTSファイルを用意します。
typescript
1// コンポーネントでそのまま使えるよう、interfaceにて型として定義
2export interface AppConstInterface {
3 readonly COMPANY_NAME: string;
4 // 他にも定数定義
5}
6
7// コンポーネントでもそのまま使えるよう、変数として定義
8export const AppConst: AppConstInterface = {
9 COMPANY_NAME: 'capsule INC.',
10 // 他にも定義
11}
コンポーネントで使うには、下記です。
typescript
1import { AppConst, AppConstInterface } from '上記ファイルへの相対パス';
2
3// 他必要な手続きなどは省略
4
5export class AppComponent implements OnInit {
6 public AppConst: AppConstInterface = AppConst;
7
8 constructor(){
9 // 後は、コンポーネントのHTML内で使用することが可能
10 }
11}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/21 08:29