The attribute 'NameNews' is not recognized in the specified type when running ng build --prod

Definition

export interface  INewsModule{

   IDNews:number;
   IDCategoery:number; 
   NameNews:string; 
   TopicNews:string; 
   DateNews?:Date;
     ImageCaption:string;
    ImageName:string ;


}

Implementation

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

      <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());
      }
   

Incorporating routing into the project

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

The project runs successfully

However, when deploying the project using

ng build --prod errors are displayed

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

Answer №1

The issue arises due to the 'items' variable being defined as an array of elements of type 'INewsModule' within the component. You may need to iterate through this array or consider modifying the data type of this variable.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with utilizing addEventListener("load") in Firefox in conjunction with <iframe>

I've encountered an issue with my iframe when it is used as the target for a form. In all major browsers, except for Firefox, the iframe successfully removes the main element upon pressing the submit button. However, in Firefox, the main element is re ...

"Implementing a feature in React JS react-table to dynamically add a new column when a

I'm struggling to add a new column to react-table when a button is clicked. Even after re-rendering the table with a flag, I can't seem to add the new column. Can anyone suggest where I might be going wrong? Here's the link to the executable ...

Transform the display format of the input type date field from 'MM/DD/YYYY' to 'February 5, 2012' in a React.js application using Material-UI's TextField component

https://i.stack.imgur.com/9p7Mz.jpg I am working with a material-ui/ TextField date component and I am looking to maintain the current style and input method, but I need to adjust how the entered value is displayed to the 'en-us' format. const o ...

Tips for utilizing process.stdin in Node.js with Javascript?

Currently, I'm developing a Javascript-based poker game that is designed to process standard input in the following manner: https://i.stack.imgur.com/D1u15.png The initial line of input will consist of an integer indicating the total number of playe ...

How can I showcase an SVG icon received in base64 format using an img tag?

Having trouble displaying SVG/base64 encoded images through the img tag. Here is the issue at hand: Receiving iconData (as a string) from the server. Attempting to display it in my component. No issues with step 1. Encountering a broken image sign with s ...

How to implement setState within a Promise function using useEffect in React functional components with hooks?

I am struggling to set the value of a hook within a Promise function inside a useEffect(), and then store the returned promise value in the fruit hook so that it can be accessed in the return function of MyComponent() This is what I have attempted so far: ...

The reason behind the successful execution of the final .then in promise chaining

I am new to JavaScript and have encountered an interesting problem with the following code. Even though I haven't returned anything from the .then method, the last .then (blue color) works instead of the first one (red color). Can someone explain why ...

Even after refreshing the page, Chrome stubbornly insists on showing the old data

I've been working on a single-page application where one page triggers server requests every time it loads. After making changes and deploying them, I noticed that the live version of the application was not reflecting the updates. Even though the cha ...

XHR object encountered a 404 error while attempting a GET request with an unknown URI component name

Currently, I am attempting to design a text box that triggers a server query as soon as a character is entered into it. However, I am encountering an error message that is puzzling me: Traceback (most recent call last): File "/Users/sahandzarrinkoub/Do ...

Using ng-style to apply a background image with a dynamic id

Hey there, I'm facing an issue here. The link provided below seems to not be working properly. Even though the id is set correctly within the scope, it seems like there might be a parsing error occurring. Any thoughts on what might be causing this pro ...

Using AngularJS location.path for unique custom URLs

Control Code: $scope.$on('$locationChangeStart', function () { var path = $location.path(); var adminPath = '/admin/' ; if(path.match(adminPath)) { $scope.adminContainer= function() { return true; }; }); HTML <div clas ...

What are the steps for skipping, sorting, and limiting with dynamoose?

After being familiar with MongoDB and mongoose, I am now exploring dynamoose for my app. In order to replicate the below-shown mongoose query using dynamoose, how can I write it? Specifically, I want to achieve the same functionality as the following mong ...

What factors contribute to the variations in results reported by Eslint on different machines?

We initially utilized tslint in our project but recently made the switch to eslint. When I execute the command "eslint \"packages/**/*.{ts,tsx}\"" on my personal Windows machine, it detects 1 error and 409 warnings. Surprising ...

Click on the photo and drag your mouse outside of it to zoom out [Angular2]

HTML <div class="zoomPhoto" *ngIf="zoomed" (click)="unZoomPhoto()"> <img src="{{currentPhoto}}" [style.margin-left.px]="-(zoomedPhotoWidth/2)" [style.margin-top.px]="-(zoomedPhotoHeight/2)" #photo /> </div> CSS .zoomPhoto{ backg ...

Uncheck all boxes except for the required or disabled boxes in Angular

HTML: <mat-selection-list #selectedColumns [(ngModel)] ="selectedOptions"> <div class= "content-section"> <mat-expansion-panel> <mat-expansion-panel-header> ...

Having Trouble Finding Vue Component Definition Using Vite Alias in Import Path

When I click on the Component within the code snippet: import Component from '@/components/Component.vue'; I am unable to navigate to its definition when using vite alias. Seeking a potential solution. ...

Make Bootstrap Panel Full Width with Highcharts Data

I am currently working on displaying graphs using the Highcharts library on three televisions. All televisions have a FULL HD resolution of 1920 x 1080. I have one Bootstrap panel containing a graph in the panel-body. <div class="panel panel-blue"> ...

Every time I attempt to install a package, I encounter an NPM unmet peer dependency issue

Entering the complex world of NPM for the first time has been quite a challenge. After running create-react-app, the installation process is almost complete except for some warning messages: yarn add v1.17.3 [1/4] Resolving packages... warning react-scri ...

Dropdown with multiple selections organized in a hierarchical structure

I am in need of the following : Implement a drop-down menu that reflects hierarchical parent-child relationships. Include a checkbox for each node to allow for selection. If all child nodes are selected, their parent node should be automatically ch ...

Is there a way to verify the functionality of DigitalOcean features using doctl before transitioning to a live environment?

As a newcomer to using DigitalOcean Functions, I have set up some JavaScript namespaces using the doctl serverless command. My main query is regarding testing DigitalOcean functions locally before deploying them to production. Is there a way to do this wit ...