简体   繁体   English

Angular 7 错误 RangeError:超出最大调用堆栈大小

[英]Angular 7 error RangeError: Maximum call stack size exceeded

I am trying to learn angular by following the official tutorial but when following steps for hero component and hero detail component , it raises an error "RangeError: Maximum call stack size exceeded".我正在尝试按照官方教程学习角度,但是在执行hero componenthero detail component的步骤时,它会引发错误“RangeError:超出最大调用堆栈大小”。

The hero.component.html : hero.component.html

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

The detail component : detail component

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

The hero component hero component

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

The hero.detail component hero.detail component

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without an error需要提一提的是,当<app-heroes></app-heroes>被评论时,列表页加载无误

错误信息截图 any help is appreciated任何帮助表示赞赏

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

This happened when I was subscribing to an observable more frequently than required.这发生在我比要求更频繁地订阅 observable 时。 I was subscribing to the below observable on every Enter key press,每次按 Enter 键时,我都订阅了以下可观察的内容,

this.filteredOptions.subscribe((res) => this.addSelectedContacts(event, res[keyManager.activeItemIndex]))

This was obviously not required, I had to limit the observable to only get the first emission by adding pipe( take(1) ) as,这显然不是必需的,我不得不通过添加 pipe( take(1) ) 来限制 observable 仅获得第一个发射,

this.filteredOptions.pipe(take(1)).subscribe((res) => this.addSelectedContacts(event, res[keyManager.activeItemIndex]))

You might also use the swithMap operator syntax to dismiss previous subscriptions.您还可以使用swithMap运算符语法来取消以前的订阅。

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

am trying to learn angular by following the official tutorial ( https://angular.io/tutorial/ ) but when following steps for hero component and hero detail component, it raises an error "RangeError: Maximum call stack size exceeded" .我试图通过遵循官方教程( https://angular.io/tutorial/ )学习angular,但是当按照英雄组件和英雄详细信息组件的步骤进行操作时,会引发错误“ RangeError:超出最大调用堆栈大小”。

the hero.component.html and detail code is as under: hero.component.html和详细代码如下:

<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<!-- 
<app-hero-detail [hero]="selectedHero"></app-hero-detail> -->


<app-heroes></app-heroes>

for detail:有关详细信息:

<div *ngIf="hero">

  <h2>{{hero.name}} Details</h2>
  <div><span>id: </span>{{hero.id}}</div>
  <div>
    <label>name:
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </label>
  </div>

</div>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>

hero component英雄组成

import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HEROES } from '../mock-heroes';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
  heroes: Hero[];

  selectedHero: Hero;

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroes = this.heroService.getHeroes();
  }

  onSelect(hero: Hero): void {
    this.selectedHero = hero;
  }

}

hero.detail component hero.detail组件

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;
  constructor() { }

  ngOnInit() {
  }

}

one thing to mention is that when <app-heroes></app-heroes> is commented, the list page is loaded without error要提及的一件事是,在对<app-heroes></app-heroes>进行注释时,将加载列表页面而不会出现错误

错误消息截图 any help appreciated任何帮助表示赞赏

Angular 12角 12

I encounter this on a infinite loop which causes ui to change on every iteration.我在无限循环中遇到这个问题,这会导致 ui 在每次迭代时都发生变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误范围错误:超出最大调用堆栈大小 [Angular] - ERROR RangeError: Maximum call stack size exceeded [Angular] 错误RangeError:超出最大调用堆栈大小(Angular 6) - ERROR RangeError: Maximum call stack size exceeded (Angular 6) angular 5递归模板错误RangeError:超出最大调用堆栈大小 - angular 5 recursive template ERROR RangeError: Maximum call stack size exceeded in 角度2:未捕获(承诺):RangeError:超出最大调用堆栈大小RangeError:超出最大调用堆栈大小 - Angular 2 :Uncaught (in promise): RangeError: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded RangeError:调用堆栈的最大大小超出了Angular 5 Router - RangeError: Maximum call stack size exceeded Angular 5 Router RangeError:超出最大调用堆栈大小(在angular2中) - RangeError: Maximum call stack size exceeded in angular2 Angular HttpInterceptor RangeError:超出最大调用堆栈大小 - Angular HttpInterceptor RangeError: Maximum call stack size exceeded Angular 2 Lazy Loading:RangeError:超出最大调用堆栈大小 - Angular 2 Lazy Loading : RangeError: Maximum call stack size exceeded RangeError:超出最大调用堆栈大小延迟路由 Angular 2 - RangeError: Maximum call stack size exceeded Lazy routing Angular 2 错误 RangeError:Object.getApps 超出了最大调用堆栈大小 - ERROR RangeError: Maximum call stack size exceeded at Object.getApps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM