Angular InjectionToken会产生;静态解析符号值时遇到错误“;
我正在尝试使用Ionic cordova build ios--prod 一切都很好,但突然(我猜是在包更新之后)我无法再构建了 我认为这个错误是由app.config.ts中的一个InjectionToken引起的,我是根据它编写代码的 app.config.tsAngular InjectionToken会产生;静态解析符号值时遇到错误“;,angular,typescript,ionic-framework,ionic2,ionic3,Angular,Typescript,Ionic Framework,Ionic2,Ionic3,我正在尝试使用Ionic cordova build ios--prod 一切都很好,但突然(我猜是在包更新之后)我无法再构建了 我认为这个错误是由app.config.ts中的一个InjectionToken引起的,我是根据它编写代码的 app.config.ts import { InjectionToken } from '@angular/core'; export interface OneSignalConfig { apiKey: string }; // PROD Con
import { InjectionToken } from '@angular/core';
export interface OneSignalConfig {
apiKey: string
};
// PROD Config
export const ONESIGNAL_CONFIG: OneSignalConfig = {
apiKey: '**apiKey**'
};
export const firebaseConfig = {
...
};
export const mixpanelToken = "**mytoken**";
// COMMON
export let ONESIGNAL_CONFIG_TOKEN = new InjectionToken<OneSignalConfig>('onesignal.config');
在尝试构建时,这会产生以下问题:
[16:10:19] ngc started ...
[16:10:27] typescript error
Error encountered resolving symbol values statically. Could not resolve ./app-config.ts relative to
/Users/me/myproj/src/app/app.module.ts., resolving symbol
AppModule in /Users/me/myproj/src/app/app.module.ts,
resolving symbol AppModule in
/Users/me/myproj/src/app/app.module.ts, resolving symbol
AppModule in /Users/me/myproj/src/app/app.module.ts
Error: The Angular AoT build failed. See the issues above
at /Users/me/myproj/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:237:55
at step (/Users/me/myproj/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:32:23)
at Object.next (/Users/me/myproj/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:13:53)
at fulfilled (/Users/me/myproj/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:4:58)
[16:10:27] copy finished in 7.84 s
但是它可以与
服务
、运行
和仿真
。。。它快把我逼疯了试着把它简化成这样:
import { InjectionToken } from "@angular/core";
export let APP_CONFIG= new InjectionToken<AppConfig >('app.config');
export interface AppConfig {
apiKey: string
// Any other constants you want here.
}
export const AppConstants: AppConfig = {
apiKey: '**apiKey**'
// Any other values you want here matching above interface.
}
然后在组件中:
...
import { Inject } from '@angular/core';
import { APP_CONFIG, AppConfig } from '../../app/app.config';
...
constructor(@Inject(APP_CONFIG)
private config: AppConfig,
) {
console.log(this.config.apiKey) // do something with your constants.
}
导入语句中不应包含文件扩展名。从app.module.ts中删除
.ts
。这应该行得通
import { firebaseConfig, ONESIGNAL_CONFIG, ONESIGNAL_CONFIG_TOKEN } from './app-config';
我在ts
中收到了不同的错误消息,因此您必须使用较旧的角度版本
...
import { Inject } from '@angular/core';
import { APP_CONFIG, AppConfig } from '../../app/app.config';
...
constructor(@Inject(APP_CONFIG)
private config: AppConfig,
) {
console.log(this.config.apiKey) // do something with your constants.
}
import { firebaseConfig, ONESIGNAL_CONFIG, ONESIGNAL_CONFIG_TOKEN } from './app-config';