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

The functionality of tinymce setContent can only be activated by directly clicking on it

Everything is running smoothly with the code below: $('.atitle').on('click', function(){ console.log('323'); tinymce.get("ed").setContent("<p>lorem ipsum</p>"); // it's working ...

Identifying the various types in Typescript

In the process of developing a solution for Excel involving data from an Office API, I encountered the challenge of distinguishing between different types that a function can return. Specifically, the data retrieved as a string may belong to either a "Cell ...

Guide to activating a reaction following an occurrence in a React component

I have started developing a React application that loads blog posts along with their associated comments. The challenge I am facing is how to trigger a refresh of the comments component and display the new comment immediately after it has been submitted. ...

What is the method of displaying a querystring on my Angular view page without relying on a controller?

My experience lies in utilizing AngularJS 1. This excerpt showcases the stateprovider configuration present in my config.js file: JavaScript .state('projects', { abstract: true, url: "/projects", templateUrl: "views/common/master_pa ...

How can Typescript help enhance the readability of optional React prop types?

When working with React, it is common practice to use null to indicate that a prop is optional: function Foo({ count = null }) {} The TypeScript type for this scenario would be: function Foo({ count = null }: { count: number | null }): ReactElement {} Wh ...

Customized style sheets created from JSON data for individual elements

One of the elements in the API requires dynamic rendering, and its style is provided as follows: "elementStyle": { "Width": "100", "Height": "100", "ThemeSize": "M", "TopMargin": "0", " ...

Utilize the HTML canvas to sketch on an image that has been inserted

I have a HTML canvas element within my Ionic application. <canvas id="canvas" color="{{ color }}" width="800" height="600" style="position:relative;"></canvas> Within this canvas, I am loading an image. Below is the code snippet from the con ...

Creating XML files using Node.js

What are some effective methods for generating XML files? Are there tools similar to the Builder in Rails, or any other recommended approaches? Appreciate any insights! ...

Instructions on filling the star icon with color upon clicking the button

Currently working on a project using codeIgniter where I have a form for rating products. I am facing an issue where, upon clicking the star button, only the border color changes to yellow while the center of the button remains white. Can someone please g ...

Ways to enhance a Vue component using slots

I am looking to enhance a third-party library component by adding an extra element and using it in the same way as before. For example: <third-party foo="bar" john="doe" propsFromOriginalLibrary="prop"> <template v ...

Tips on passing an object as data through Angular router navigation:

I currently have a similar route set up: this.router.navigate(["/menu/extra-hour/extra-hours/observations/", id]) The navigation is working fine, but I would like to pass the entire data object to the screen in order to render it using the route. How can ...

Can someone provide guidance on integrating UI components with Angular 8?

I have developed my own custom component called app-button.ts. This component is responsible for checking the current user's roles and rendering the button only if it matches the defined roles. The ButtonType property is used to specify the style of ...

"RecognitionAudio variable missing" and "InactiveRpcError occurred" [Utilizing the Google text-to-speech API]

I have a goal I'd like to achieve. A user communicates with a web browser. The web browser records the user's voice as a WAV file using Recorder.js and sends it to a server running on Google App Engine Standard environment with Python 3.7. The ...

An AJAX event handling function returns a null value upon invocation

Recently, I've been working on a function named 'getAuthor' which includes an AJAX event. Here's the code snippet: function getAuthor(id){ $.get('http://www.connectnigeria.com/articles/wp-json/wp/v2/users/74',function(e){ ...

Creating an object efficiently by defining a pattern

As a newcomer to Typescript (and Javascript), I've been experimenting with classes. My goal is to create an object that can be filled with similar entries while maintaining type safety in a concise manner. Here is the code snippet I came up with: le ...

Is there a way to display errors during jQuery validation?

Is there a specific function that can provide all error messages generated during form validation? I attempted to use the defaultshowerrors() function, but it only shows errors for the current element being validated. Is there a way to retrieve all error ...

no visible text displayed within an input-label field

Currently, I have started working on a multi-step form that is designed to be very simple and clean. However, I am facing an issue where nothing is being displayed when I click on the next arrow. I am puzzled as to why it's not even displaying the te ...

Next.JS-13 has encountered an inappropriate middleware in its App Based Routing functionality

I am currently working on developing a user authentication system that includes features for Login, Signup, and Logout. As part of this project, I have created a middleware.ts file in the src directory, which is located next to the app directory. Below is ...

The chai property "matchSnapshot" is not valid

After following the instructions provided at this link, I am now in the process of writing basic Jest tests for my React application that uses the Create-React-App starter kit. I came across a recommendation mentioned here that advises against installing ...

Issue encountered while appending query parameters to HTTP request

While utilizing mock data and the InMemoryDbService similar to the tour of heroes example, I encountered an issue when passing HttpParams. The data loads successfully without any parameters, but as soon as I add them, I receive a 500 response with the erro ...