gpt4 book ai didi

Angular 2未使用的标签错误

转载 作者:太空狗 更新时间:2023-10-29 17:02:21 25 4
gpt4 key购买 nike

我正在尝试按照 Angular 2 网站上的官方教程进行操作。 This tutorial

我在 atom IDE 中遇到以下错误:

Unused label.at line 8 col 1

Cannot assign to 'Hero' because it is not a variable.at line 8 col 7

以下是我的代码:

import { Component } from '@angular/core';

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

hero: Hero = {
id: 1,
name: 'Windstorm'
};

@Component({
selector: 'my-app',
template: `<h1>{{title}}</h1>
<h2>{{hero.name}} details!</h2>`
})

export class AppComponent {
title = 'Tour of Heroes';
hero = 'Windstorm';
}

结果:

Screen Shot

我做错了什么?感谢您的帮助。

最佳答案

根据您所指的教程,hero 字段初始化应该在 AppComponent 内部:

import { Component } from '@angular/core';

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

@Component({
selector: 'my-app',
template: `<h1>{{title}}</h1>
<h2>{{hero.name}} details!</h2>`
})

export class AppComponent {
title = 'Tour of Heroes';
hero: Hero = {
id: 1,
name: 'Windstorm'
};
}

关于Angular 2未使用的标签错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41849929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com