错误类型错误:无法读取未定义的属性“_id”

乔什·麦卡特

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

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

我知道 python API 正在工作,因为我已经在邮递员中对其进行了测试。

这是我收到的错误。

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>

非常新的 Python 和 angular,非常感谢任何帮助。

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

劳埃德·尼科尔森

改变变量business,以score与ngFor指令枚举时。应该做的伎俩。显示数据更改Scores.datescore.date枚举时,您需要对字母使用精确的枚举器字母。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

角度:错误类型错误:无法读取未定义的属性___

AngularJS类型错误:无法读取未定义的属性“ GET()”

错误类型错误:无法读取未定义的属性“标题”

错误类型错误:无法读取未定义的属性“...”

错误类型错误:无法读取未定义的属性“填充”

类型错误:无法读取未定义的属性“indexOf”,无法读取未定义的属性“toLowerCase”

错误类型错误:无法读取未定义的属性“stateName”

错误类型错误:无法读取未定义的属性“s_id”

错误类型错误:无法读取未定义的属性

错误类型错误:无法读取未定义的属性“getUsers”

“类型错误:无法读取未定义的属性‘名称’”错误

类型错误:无法读取未定义的属性“类型”

错误类型错误:无法读取未定义的属性“列表”

错误类型错误:无法读取未定义的属性“ID”(Angular 8)

类型错误:无法读取未定义的属性“ChangeClassName”

类型错误:无法读取未定义 NodeJS 的属性“样式”

渲染错误:“类型错误:无法读取未定义的属性‘’”

类型错误:无法读取未定义错误的属性“_id”

错误类型错误:无法读取未定义的属性“doc”

类型错误:无法读取未定义 ReactJs 的属性“_id”?

类型错误:无法读取未定义 Flutter 的属性“id”

类型错误:无法在 setTimeout() 中读取未定义的属性“then”

**错误** 类型错误:无法读取未定义的属性“替换”

类型错误:无法读取未定义的属性(读取“图像”)

类型错误:无法读取未定义的属性(读取“缓存”)

类型错误:无法读取未定义的属性(读取“暗”)

类型错误:无法读取未定义的属性(读取“reduce”)

类型错误:无法读取未定义的属性(读取“类型”)

类型错误:无法读取未定义读取“2”的属性