Angular 5“ng build”显示没有错误“ng build --prod”有很多错误

时间:2018-05-14 19:48:40

标签: angular

我知道以前曾经问过,但我读到的内容并没有帮助。

ERROR in src/app/catalog/product/product.component.html(19,43): : Property 'length' does not exist on type 'object'. src/app/catalog/product/product.component.html(36,39): : Property 'specs' does not exist on type 'Object'. src/app/catalog/product/product.component.html(58,8): : Property 'config' does not exist on type 'ProductComponent'. Did you mean 'Configs'? src/app/catalog/product/product.component.html(59,14): : Property 'config' does not exist on type 'ProductComponent'. Did you mean 'Configs'? src/app/catalog/product/add/add.component.html(14,8): : Property 'pre_configs' does not exist on type 'object'. src/app/catalog/product/add/add.component.html(30,28): : Property 'sets' does not exist on type 'object'. src/app/catalog/product/add/add.component.html(70,32): : Property 'price' does not exist on type 'object'. src/app/catalog/product/add/add.component.html(70,32): : Property 'price' does not exist on type 'object'. src/app/navigation/mini/mini-search/mini-search.component.html(9,5): : Property 'searchText' does not exist on type 'MiniSearchComponent'. src/app/navigation/mini/mini-search/mini-search.component.html(13,5): : Property 'searchText' does not exist on type 'MiniSearchComponent'. src/app/catalog/single/single.component.html(5,24): : Property 'id' does not exist on type 'any[]'. src/app/catalog/single/single.component.html(74,25): : Property 'id' does not exist on type 'any[]'. src/app/navigation/maga/maga.component.html(5,8): : Property 'name' does not exist on type 'any[]'. 之后没有错误

在'ng build --prod'之后

--prod

这是一个非常烦人的问题。我开始逐一查看错误并将继续,但刚刚完成的错误是有意义的,这条路线将花费我几个小时。任何人都可以告诉我从哪里开始或为什么在<div *ngIf="sample?.specs"> <div class="spec-section" *ngFor="let section of sample.specs"> <h2>{{section.name}}</h2> </div> </div> 之后出现新的错误?

更新:其中一个错误

的示例

在我的组件html中

ng build --prod
ERROR in ../product/product.component.html(37,12): : Property 'specs' does not exist on type 'Object'.

后出现

错误

sample

以下是获取constructor(public configsService: ConfigsService) { this.sample = configsService.sample_data; }

的组件代码
ng serve

ng build或部署ng build --prod后,fronend看起来/工作正常。错误只会在subscribe

中弹出

1 个答案:

答案 0 :(得分:2)

每个错误都有自己的修复方式,主要与我从服务中获取数据的方式有关。

修复的示例1

constructor(public configsService: ConfigsService) {
    this.sample = configsService.sample_data;
}

应该是..

get sample() { return this.configsService.Sample_data; }
constructor(public configsService: ConfigsService) {}

为了实现这一点,我必须加入服务

import { Sample } from '../_data/sample_product';

@Injectable()
export class ConfigsService {
    sample_data = Sample;
    constructor()  {}
    get Sample_data() { return this.sample_data; }
}

修复的示例2

<强> HTML

<a (click)="config=!config" class="button">Configure</a>

ng serveng build但不在ng build --prod中有效,因为我没有在组件中声明config。像这样config:boolean;

(answer.helped) ? upvote() : comment();