简体   繁体   English

Angular 5构建错误“类型上不存在属性”

[英]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 gives me an error : ng build --prod给我一个错误:

ERROR in src/app/projects/projects.service.ts(11,33): error TS2339: Property 'wpBase' does not exist on type '{ production: boolean; }'.

How can I fix this? 我怎样才能解决这个问题? The app works fine, I'm trying to implement Angular Universal using this guide: https://github.com/angular/angular-cli/wiki/stories-universal-rendering 该应用程序工作正常,我正在尝试使用此指南实现Angular Universal: https//github.com/angular/angular-cli/wiki/stories-universal-rendering

You probably forgot to set the wpBase property in environment.prod.ts ... 您可能忘了在environment.prod.ts中设置wpBase属性...

Check both your environment.ts and environment.prod.ts and see if you have set the wpBase correctly. 检查您的environment.tsenvironment.prod.ts ,看看您是否正确设置了wpBase

Quick fix is to type the environment as any: 快速修复是将环境键入任何:

@Injectable()
export class ProjectsService {
  private _wpBase = (environment as any).wpBase;
}

Proper fix would be to add type definition for your environment object. 正确的解决方法是为您的环境对象添加类型定义。

interface AppEnv {
   production: boolean;
   wpBase: // whatever is the correct type
}
export const environment: AppEnv = {
  production: false,
  wpBase: // whatever is the value
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM