gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:58:30 25 4
gpt4 key购买 nike

我知道之前有人问过这个问题,但我阅读的内容没有任何帮助。

ng build 之后没有错误

在“ng build --prod”之后

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[]'.

这是一个非常烦人的问题。我开始一个一个地查看错误并将继续,但刚刚完成的错误是有道理的,这条路线将花费我几个小时。谁能告诉我从哪里开始或为什么在 --prod 之后出现新错误?

更新:其中一个错误的例子

在我的组件 html 中

<div *ngIf="sample?.specs">
<div class="spec-section" *ngFor="let section of sample.specs">
<h2>{{section.name}}</h2>
</div>
</div>

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

期间弹出

最佳答案

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

修复示例 1

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

应该是..

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

为了让它工作,我必须在服务中加入一个 get

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() : 评论();

关于Angular 5 "ng build"显示没有错误 "ng build --prod"有很多错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50337954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com