admin管理员组文章数量:1026989
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
2 Answers
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
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
2 Answers
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
本文标签:
版权声明:本文标题:javascript - Type {...} is missing the following properties from type 'any[]': length,pop,push,concat, and 28 mo 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1740932903a1799104.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论