Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 错误类型错误:无法读取属性'_id';未定义的_Python_Angular - Fatal编程技术网

Python 错误类型错误:无法读取属性'_id';未定义的

Python 错误类型错误:无法读取属性'_id';未定义的,python,angular,Python,Angular,我知道有这样的问题。我已经阅读了答案,无法通过它们找到解决办法 我正在创建一个带有角度前端的python API后端。我的数据集存储在mongo DB中 我知道pythonapi正在工作,因为我已经在postman中对它进行了测试 这是我收到的错误 ScoresComponent.html:9 ERROR TypeError: Cannot read property '_id' of undefined at Object.eval [as updateDirectives] (ScoresC

我知道有这样的问题。我已经阅读了答案,无法通过它们找到解决办法

我正在创建一个带有角度前端的python API后端。我的数据集存储在mongo DB中

我知道pythonapi正在工作,因为我已经在postman中对它进行了测试

这是我收到的错误

ScoresComponent.html:9 ERROR TypeError: Cannot read property '_id' of undefined
at Object.eval [as updateDirectives] (ScoresComponent.html:10)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:45259)
at checkAndUpdateView (core.js:44271)
at callViewAction (core.js:44637)
at execEmbeddedViewsAction (core.js:44594)
at checkAndUpdateView (core.js:44272)
at callViewAction (core.js:44637)
at execComponentViewsAction (core.js:44565)
at checkAndUpdateView (core.js:44278)
at callViewAction (core.js:44637)
这是我的web.service.ts代码

import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Subject} from 'rxjs';


@Injectable()
export class WebService{

    private score_private_list;
    scoresSubject = new Subject();
    scores_list = this.scoresSubject.asObservable();

    private score_private;
    scoreSubject = new Subject();
    score = this.scoreSubject.asObservable();

    private reviews_private_list;
    reviewsSubject = new Subject();
    reviews_list = this.reviewsSubject.asObservable();

    constructor(private http: HttpClient) {}


    getscores(page){
        return this.http.get('http://localhost:5000/api/v1.0/scores?pn=' + page)
            .subscribe(response => {
                this.score_private_list = response;
                this.scoresSubject.next(this.score_private_list);
            })
    }

    getscore(id){
        return this.http.get('http://localhost:5000/api/v1.0/scores/' + id)
            .subscribe(response => {
                this.score_private_list = response;
                this.scoreSubject.next(this.score_private);
            })
    }

    getReviews(id){
        return this.http.get('http://localhost:5000/api/v1.0/scores/' + id + '/reviews')
            .subscribe(response => {
                this.reviews_private_list = response;
                this.reviewsSubject.next(this.reviews_private_list);
            })
    }
}
这是我的scores.component.ts代码

import { Component } from '@angular/core';
import { WebService } from './web.service';
import { Message } from '@angular/compiler/src/i18n/i18n_ast';

@Component({
  selector: 'scores',
  templateUrl: './scores.component.html',
  styleUrls: ['./scores.component.css']
})
export class ScoresComponent {

  constructor(private webService: WebService) { }

  ngOnInit() {
    if (sessionStorage.page){
      this.page = sessionStorage.page;
    }
    this.webService.getscores(this.page);


  }

  nextPage(){
    this.page = Number(this.page) + 1;
    sessionStorage.page = Number(this.page);
    this.webService.getscores(this.page);
  }

  previousPage(){
    if (this.page>1){
    this.page = Number(this.page) -1;
    sessionStorage.page = Number(this.page);
    this.webService.getscores(this.page);
    }
    else{window.alert("Already on first page")}
  }

  scores_list;
  page = 1;

}

这是我的scores.component.html代码

<div class="jumbotron">
    <h1>Premier League Match Scores</h1>
</div>

<div class="container">
    <div class="row">
        <div class="col-sm-12">
            <div *ngFor="let business of webService.scores_list | async">
                <div class="card text-white bg-primary mb-3"
                [routerLink] = "['/scores', score._id]"
                style = "cursor: pointer;">
                    <div class="card-header">
                        {{ Scores.date }}
                    </div>

                </div>
            </div>
            <div class = "row">
                <div class = "col-sm-6">
                    <button class="btn_primary" (click) = "previousPage()">
                        Previous
                    </button>
                </div>
                <div class = "col-sm-6 text-right">
                    <button class="btn_primary" (click) = "nextPage()">
                        Next
                    </button>
                </div>
            </div>

        </div>


    </div>
</div>

英超比赛分数
{{Scores.date}
以前的
下一个
非常新的Python和angular,非常感谢您的帮助


我不确定“_id”是未定义的还是完全不同的问题。我一直在尝试查看我的所有组件名称是否匹配,以及我的列表变量名称是否相同。我似乎找不到问题所在

使用ngFor指令枚举时,将变量
business
更改为
score
。我们应该做到这一点。要显示数据,请将
score.date
更改为
score.date
。在枚举时,需要逐个使用精确的枚举器

我看不出你在哪里枚举一个叫做“score”的变量?你把统计员叫做“生意”,所以你不是认真的吗?我甚至没意识到它还在说生意。我的意思是把它作为分数的分数。_id.有了这个改变,我没有收到任何错误,尽管没有显示任何数据。当我改变你所说的内容时,数据正在显示更新,似乎第二双眼睛永远是最好的调试技术,谢谢。必须为所有需要的数据更改一些其他文本。现在在不同的代码段上出现相同的问题。尝试执行与我相同的调试过程。再次感谢