javascript - Type {...} is missing the following properties from type 'any[]': length,pop,push,concat, and 28 mo

I have this error:Type {...} is missing the following properties from type 'any[]': length,po

I have this error:

    Type {...} is missing the following properties from type 'any[]': length,pop,push,concat, and 28 more

I have this error:

    Type {...} is missing the following properties from type 'any[]': length,pop,push,concat, and 28 more

I'm assigning album variable to the albumData array. Here is the code:

import { Component, OnInit } from '@angular/core';
import albumData from '../data/SearchResultsAlbum.json';

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

  album:Array<any>=[];
  
  constructor() { }

  ngOnInit(): void {
    
    this.album=albumData;
  }

}

What am I doing wrong? Thank you in advanvce!

Share Improve this question asked Mar 2, 2022 at 16:46 MaxMax 1191 gold badge1 silver badge8 bronze badges 1
  • Either your json is an object, so it won't have those properties that are array properties, or your json data needs to be parsed first anyway in order to use it as array. What do you get when you console.log the albumData? – Misha Mashina Commented Mar 2, 2022 at 16:55
Add a ment  | 

2 Answers 2

Reset to default 9
 album:any=[]; 

use this code instead of the code you have added

By default, Angular doesn't read the JSON file in the application. So we need to do some extra stuff for that. So we will create a file named 'json-typings.d.ts' inside the app folder of the project.

declare module "*.json" {
const value: any;
export default value;
}

source: https://jsonworld./demo/how-to-read-local-json-file-in-angular

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1740932903a4277357.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信