简体   繁体   中英

Identifier 'image' is not defined. 'never' does not contain such a member

Edit:: The output is added. I getting the output successfully, but I just don't know why I am getting this error. 在此处输入图像描述 I had already done this before but now I am facing this error. I had tried using "?" and ".." but still not fixing. What is this and how to fix this:: Edit ::

html

 <div class="container" *ngFor="let data of data">
     <a href="{{ data.url }}"> //error in url ( Identifier 'url' is not defined. 'never' does not contain such a member )
         <img src="{{ data.image }}"> // error in image ( Identifier 'image' is not defined. 'never' does not contain such a member )
     </a>
 </div>

ts file

import { Component, OnInit } from '@angular/core';
import { ApiService } from 'src/app/services/api.service';

@Component({
  selector: 'app-technology',
  templateUrl: './technology.component.html',
  styleUrls: ['./technology.component.css']
})
export class TechnologyComponent implements OnInit {

  data = [];

  constructor(private apiservice : ApiService) { }

  ngOnInit() {
    this.apiservice.getTechUrl().subscribe(async (data : any) => {
      this.data = await data.articles
    })
  }
}

I found the solution for this

I had just changed the data = []; to data: any; and there is no error and i also got the output without any error.

Error template syntax ngFor= "let data of data " ngFor can't use check point name same array data name.

Try this

<div class="container" *ngFor="let item of data">
     <a href="{{ item.url }}"> 
         <img src="{{ item.image }}"> 
     </a>
 </div>

hope help you

I found the solution

I just changed the data = []; to data: any; in the.ts file and then there is not error;

but I still don't know what is the exact reason for that error. I don't if I am right about this the Json file which I was receiving is of type object and storing inside the data of array given me the error but after changing the to data: any; I am not giving any specific type in here, it may be of any type so error is gone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM