简体   繁体   English

使用ng build --prod的类型不存在属性“ NameNews”

[英]Property 'NameNews' does not exist on type using ng build --prod

interface 接口

 export interface INewsModule{ IDNews:number; IDCategoery:number; NameNews:string; TopicNews:string; DateNews?:Date; ImageCaption:string; ImageName:string ; } 

Component 零件

 import { Component, OnInit, Input, Injectable } from '@angular/core'; import { NewsService } from '../../serv/news.service'; import { ActivatedRoute } from '@angular/router'; import { INewsModule } from '../../Class/i-news/i-news.module'; import { FormsModule } from '@angular/forms'; import {Http , Response , Headers , RequestOptions ,RequestMethod, } from '@angular/http'; import { ISubscription } from 'rxjs/Subscription'; import { HttpClient } from '@angular/common/http'; import { retry } from 'rxjs-compat/operator/retry'; @Injectable({ providedIn: 'root' }) @Component({ selector: 'app-detalis', templateUrl: './detalis.component.html', styleUrls: ['./detalis.component.scss'], providers:[NewsService] }) export class DetalisComponent implements OnInit { public Newsmodule : INewsModule[]; subscription: ISubscription; statusMessage: string = 'please wait Loading data ... :D'; items :INewsModule[]=[]; constructor(public _NewsService : NewsService,public _activeRoute: ActivatedRoute,public _HttpClient: HttpClient ) { } ngOnInit() { let id : number = this._activeRoute.snapshot.params['id']; this._NewsService.getdetails(id).retryWhen((err) => { return err.scan((retryCount) =>{ retryCount +=1; if(retryCount < 6 ){ this.statusMessage ='Retrying .....Attept #' + retryCount; return retryCount; } else { throw (err); } }, 0).delay(1000) }) .subscribe((newsdata) => { if(newsdata == null){ this.statusMessage = 'Employee code does not exist'; } else { this.items = newsdata } }, (error) =>{ this.statusMessage = "please try again after sometime" console.log(error); }) } } 
Template DetalisComponent Template DetalisComponent Template DetalisComponent Template DetalisComponent Template DetalisComponent Template DetalisComponent Template DetalisComponent Update 模板DetalisComponent模板DetalisComponent模板DetalisComponent模板DetalisComponent模板DetalisComponent模板DetalisComponent模板DetalisComponent更新

  <table class="blueTable" style="height: 212px;" width="333"> <thead> <tr> <th>NameNews</th> <th>TopicNews</th> <th>Date</th> <th>Image</th> </tr> </thead> <tfoot> <tr> <td colspan="4"> <div class="links">&nbsp;</div> </td> </tr> </tfoot> <tbody> <tr > <td>{{items.NameNews}}</td> <td>{{items.TopicNews}}</td> <td>{{items.DateNews}}</td> <td><img class="" src="http://localhost:56181/Image/{{items.ImageName}}"> </td> </tr> </tbody> </table> 

 /GetdetailsNews getdetails(id:number): Observable <INewsModule[]>{ return this.http.get('http://localhost:56181/api/details/' + id).map((response: Response)=><INewsModule[]>response.json()); } 

i using routing 我使用路由

Index => allCategory => allnews => detailsNews[name,date....] using ng s --o 索引=> allCategory => allnews => detailsNews [name,date ....]使用ng s --o

project run successfully 项目成功运行

but in deploy project using 但是在部署项目中使用

ng build --prod show Errors ng build --prod显示错误

 ERROR in src\\app\\views\\home\\detalis.component.html(126,21): : Property 'NameNews' does not exist on type 'INewsModule[]'. src\\app\\views\\home\\detalis.component.html(127,23): : Property 'TopicNews' does not exist on type 'INewsModule[]'. src\\app\\views\\home\\detalis.component.html(128,23): : Property 'DateNews' does not exist on type 'INewsModule[]'. src\\app\\views\\home\\detalis.component.html(129,37): : Property 'ImageName' does not exist on type 'INewsModule[]'. 

The error come from the fact that the variable 'items' is typed as an array of elements of type 'INewsModule' (when declared in the component). 错误来自以下事实:变量“ items”的类型为“ INewsModule”类型的元素数组(在组件中声明时)。 You probably need to iterate on this array, or to change the type of this variable. 您可能需要在此数组上进行迭代,或更改此变量的类型。

暂无
暂无

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

相关问题 当我尝试使用 ng build --prod 构建应用程序时,它说“属性 'invited_by' 在类型 'any[]' 上不存在” - When i try to build app using ng build --prod it says “Property 'invited_by' does not exist on type 'any[]' ” 运行ng build时,属性“ title”在类型“ {}”上不存在-虽然prod可与ng serve一起使用 - Property 'title' does not exist on type '{}' when running ng build --prod works with ng serve though 运行 ng build --output-hashing=all --prod 时,类型“AbstractControl”上不存在属性“controls” - Property 'controls' does not exist on type 'AbstractControl' while running ng build --output-hashing=all --prod 带有 --prod 标志的 Ionic 5 构建失败 - 类型上不存在属性“翻译” - Ionic 5 build with --prod flag fails - Property 'translate' does not exist on type Angular 应用程序编译成功,但在“ng build --prod”中不存在提供错误属性 - Angular app is compiling successfully but giving errors property does not exist in 'ng build --prod' TypeScript构建错误:“ IStateParamsService”类型不存在属性 - TypeScript Build Error : Property does not exist on type 'IStateParamsService' 类型上不存在属性但属性存在 - Property does not exist on type But property exist 使用自定义类型定义时,类型上不存在属性 - Property does not exist on type when using custom type definition Angular Fail ng build --prod - Angular Failed ng build --prod ng build --prod 在 Terser 上失败 - ng build --prod is failing on Terser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM