Angular 5 个构建错误 "Property does not exist on type"
Angular 5 build error "Property does not exist on type"
import { environment } from '../../environments/environment';
import { Headers } from '@angular/http';
@Injectable()
export class ProjectsService {
private _wpBase = environment.wpBase;
ng build --prod 给我一个错误:
ERROR in src/app/projects/projects.service.ts(11,33): error TS2339: Property 'wpBase' does not exist on type '{ production: boolean; }'.
我该如何解决这个问题?该应用程序运行良好,我正在尝试使用本指南实现 Angular 通用:https://github.com/angular/angular-cli/wiki/stories-universal-rendering
您可能忘记在 environment.prod.ts...
中设置 wpBase
属性
检查你的 environment.ts 和 environment.prod.ts 看看你是否设置了 wpBase
正确。
快速解决方法是将环境键入任意:
@Injectable()
export class ProjectsService {
private _wpBase = (environment as any).wpBase;
}
正确的解决方法是为您的环境对象添加类型定义。
interface AppEnv {
production: boolean;
wpBase: // whatever is the correct type
}
export const environment: AppEnv = {
production: false,
wpBase: // whatever is the value
};
import { environment } from '../../environments/environment';
import { Headers } from '@angular/http';
@Injectable()
export class ProjectsService {
private _wpBase = environment.wpBase;
ng build --prod 给我一个错误:
ERROR in src/app/projects/projects.service.ts(11,33): error TS2339: Property 'wpBase' does not exist on type '{ production: boolean; }'.
我该如何解决这个问题?该应用程序运行良好,我正在尝试使用本指南实现 Angular 通用:https://github.com/angular/angular-cli/wiki/stories-universal-rendering
您可能忘记在 environment.prod.ts...
中设置wpBase
属性
检查你的 environment.ts 和 environment.prod.ts 看看你是否设置了 wpBase
正确。
快速解决方法是将环境键入任意:
@Injectable()
export class ProjectsService {
private _wpBase = (environment as any).wpBase;
}
正确的解决方法是为您的环境对象添加类型定义。
interface AppEnv {
production: boolean;
wpBase: // whatever is the correct type
}
export const environment: AppEnv = {
production: false,
wpBase: // whatever is the value
};