我是Angular的初学者。关于将字符串外部化的文章很多,但是没有一篇回答我的疑问。我也检查了this。我的上级告诉我要对代码中的所有字符串进行外部化。直接或硬编码的字符串我已经外部化了,但也有两个字符串数组。我将向您展示我的代码(*最小代码):
timeselector.component.html
<h2 [translate]="'timeselection.tshead'"></h2>
assets / i18 / en-Us.json
{
"App": {
...
},"Header": {
...
},"SubTabLabels": {
...
},"Errors": {
...
},"timeselection": {
"tshead": "Time selection"
}
}
这很容易。但是在我的打字稿文件中有一些数组。有人告诉我也将它们外部化。这是代码:
timeselector.component.ts
import { Component } from '@angular/core';
@Component({
...
})
export class TimeselectorComponent {
...
public arr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
public source = ['Calendar year','Year-to-date','Fiscal Year-To-Date','Fiscal Calendar Year','Rolling 12 months'];
...
}
请参见arr
和source
处有两个数组。如果可行,请帮助我将两者中的任何一个外部化。
PS:我们正在使用这两个软件包"@ngx-translate/core": "11.0.1"
和"@ngx-translate/http-loader": "4.0.0"