目前,我正在开发一个MovieTicketBooking网站,使用的是ANGLINE和ASP.NETWeb API。它在我无法修理的地方卡住了。当我试图在前端显示电影细节时,我得到了这样的错误:Error: NG0900: Error trying to diff '[object Object]'. Only arrays and iterables are allowed
。请帮我解决这个问题
Book.component.html
<div class="card">
<div class="card-body" *ngFor="let item of moviedata">
<h5 class="card-title">{{item.Title}}</h5>
<p class="card-text">{{item.Description}}</p>
<!-- <button class="btn btn-primary" (click)="getAllMovieById(item.id)">Book</button> -->
</div>
</div>
Book.component.ts
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { Movie } from 'src/app/Models/Movie';
import { MovieService } from 'src/app/shared/movie.service';
@Component({
selector: 'app-book',
templateUrl: './book.component.html',
styleUrls: ['./book.component.css']
})
export class BookComponent implements OnInit {
moviedata: Movie[] = [];
constructor(private route : ActivatedRoute , private formBuilder : FormBuilder, private _http:HttpClient, private router: Router, private movieservice : MovieService) {
this.movieservice.getMovieById(this.route.snapshot.params['id']).subscribe((result:any)=>{
this.moviedata = result;
console.log(this.moviedata);
})
}
ngOnInit(): void
{
}
}
控制台上的数据
autoOffSet: null
createdBy: 0
creationDate: "0001-01-01T00:00:00+00:00"
description: "qwerty"
entityState: 0
fare: 123
id: 1
imgPath: null
modifiedBy: null
modifiedDate: null
rowVersion: null
shows: Array(1)
0: {ticket: 12, showTime: '2022-05-23T13:09:00', showDate: '2022-05-23T00:00:00', movieId: 1, movie: {…}, …}
length: 1
[[Prototype]]: Array(0)
title: "Doctor Strange"
[[Prototype]]: Object
3条答案
按热度按时间sdnqo3pr1#
您的
moviedata
是对象,而不是数组。你应该这样做。
8fq7wneg2#
可能
result
不是类型Movie[]
。这可能会对你的想法有所帮助。6gpjuf903#
This.moviedata=结果;
结果不是对象,您应该将其解析为对象
This.moviedata=JSON.parse(Result)