[英]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); }) } }
<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"> </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.