我有一个枚举,我试图注入一个角度的应用程序类。我怎样才能让我的课程认识到这个枚举?
我不能让打字稿承认枚举的属性,并得到错误Property 'xs' does not exist on type 'appBreakpoints'
代码:
// appBreakpoints.ts file
export enum appBreakpoints {
xs = 1, // convert xs to truthy value
sm,
md,
lg,
xl,
xxl
}
// In app.module
import { appBreakpoints } from './appBreakpoints'
@NgModule({
providers: [
{ provide: appBreakpoints, useValue: appBreakpoints}
]
});
// In some service
import { appBreakpoints } from './appBreakpoints';
import { Inject } from '@angular/core';
class MyClass {
constructor(@Inject(appBreakpoints) private appBreakpoints: appBreakpoints) {
if (0 < this.appBreakpoints.xs) { // TS ERROR: Property 'xs' does not exist on type 'appBreakpoints'
console.log('something being logged');
}
}
}
我怎样才能得到打字稿识别枚举的属性,所以我可以使用它们在我的班上?
感谢。它让我的代码工作。我在app-config文件中有枚举,只是想让其他可能需要枚举的服务可用。 – Jonathan002