Muf*_*asa 12 typescript angular
我一直在这里关注文档并使用ng-cli.
我创建了以下配置文件(app-config.ts):
import { OpaqueToken } from '@angular/core';
export interface AppConfig {
supportTelephoneNumber: string;
}
export let APP_CONFIG_t = new OpaqueToken('app.config');
export const APP_CONFIG: AppConfig = {
supportTelephoneNumber: '1111 111 1111'
};
Run Code Online (Sandbox Code Playgroud)
在我的app.module.ts文件中,我有:
...
@NgModule({
declarations: [
UkCurrencyPipe,
AppComponent,
HomeComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot(ROUTES, { useHash: true }),
MaterialModule.forRoot()
],
providers: [
{ provide: APP_CONFIG_t, useValue: APP_CONFIG },
...
Run Code Online (Sandbox Code Playgroud)
我在app.component.ts文件中使用此配置,如下所示:
import { Component, Inject } from '@angular/core';
import { APP_CONFIG_t, AppConfig } from './app-config';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less']
})
export class AppComponent {
constructor(@Inject(APP_CONFIG_t) public config: AppConfig) {
callSupport(): void {
window.location.href = 'tel:+' + this.config.supportTelephoneNumber;
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用ng服务我的应用程序服务时,一切似乎工作正常,但我确实在控制台中看到这些警告我运行服务器:
./src/app/app.component.ts中的警告
40:166导出' ./app-config '中未找到'AppConfig'./src/app/app.component.ts中的警告
40:195导出' ./app-config '中未找到'AppConfig'
有谁知道这些警告意味着什么,我是否应该担心它们?
我的版本
bez*_*gon 18
根据问题https://github.com/angular/angular-cli/issues/2034的评论
有同样的问题.(尽管有警告,但工作正常)你是从文件中导出多个接口/类/ const吗?从我自己的专用文件导出每个接口后,问题停止了.
意思是如果我有一个文件有多个导出 - 我在构建中收到警告(在'../file'中找不到导出'MyInterface1')
file.ts
export interface MyInterface1 {}
export interface MyInterface2 {}
Run Code Online (Sandbox Code Playgroud)
重构后 - 没有警告
file1.ts
export interface MyInterface1 {}
Run Code Online (Sandbox Code Playgroud)
file2.ts
export interface MyInterface2 {}
Run Code Online (Sandbox Code Playgroud)