Не могу найти имя в Angular 6 - PullRequest
0 голосов
/ 26 августа 2018

Я новичок в Angular 6 и слежу за документацией по Angular с проектом тестирования.Все работает нормально, но ошибка на консоли не позволяет мне создать сборку проекта. Ошибка:

Не удается найти имя "Герой"

enter image description here

Ниже мой код.Любая помощь будет оценена.Спасибо.

/* mock-heroes.ts */  

export const HEROES: Hero[] = [
  { id: 1, name: 'Alex'},
  { id: 2, name: 'John'},
  { id: 3, name: 'Albert'},
];

/* heroes.component.ts */

import { Component} from '@angular/core';
import {HEROES} from '../mock-heroes';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent{
  heroes = HEROES;
  selectedHero: '';
  onSelect(hero: Hero): void {
     this.selectedHero = hero;
  }
}

/* heroes.component.html */

<div>
  <h2>My Heroes</h2>
  <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>
</div>

<div *ngIf="selectedHero">
  <h2>{{selectedHero.name | uppercase}} Details</h2>
  <div><span>id: </span>{{selectedHero.id}}</div>
  <div>
    <label>Name:
     <input [(ngModel)]="selectedHero.name" placeholder="Name">
    </label>
  </div>    
</div>

1 Ответ

0 голосов
/ 26 августа 2018

Это означает, что файл класса для Героя отсутствует. Вам необходимо добавить импортируемого Героя с указанного вами пути

export const HEROES: Hero[] = [
  { id: 1, name: 'Alex'},
  { id: 2, name: 'John'},
  { id: 3, name: 'Albert'},
];

пример

export class Hero {
  id: number;
  name: string;
}

и импорт как,

import { Hero } from '../hero';

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...