小编Om *_*tel的帖子

错误:类型'Hero []'上不存在属性'then'

app.component.ts文件

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [HeroService]
})

export class AppComponent implements OnInit{
  title = 'Tour of Heroes';
  heroes : Hero[ ];
  selectedHero : Hero;
  constructor(private heroService: HeroService) { }
      getHeroes(): void {
     this.heroService.getHeroes().then(heroes => this.heroes = heroes);
  };
    ngOnInit(): void {
    this.getHeroes();
  };
    onSelect(hero: Hero): void{
    this.selectedHero = hero;
  };
}
Run Code Online (Sandbox Code Playgroud)

hero.service.ts

import { Injectable } from …
Run Code Online (Sandbox Code Playgroud)

angularjs typescript angular

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

angular ×1

angularjs ×1

typescript ×1