Angular 5构建错误"属性#34;

时间:2018-04-24 10:10:43

标签: angular build universal

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 Universal:https://github.com/angular/angular-cli/wiki/stories-universal-rendering

2 个答案:

答案 0 :(得分:2)

您可能忘记在 environment.prod.ts 中设置wpBase属性...

检查您的 environment.ts environment.prod.ts ,看看您是否正确设置了wpBase

答案 1 :(得分:1)

快速修复是将环境键入任何:

@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
};