繁体   English   中英

AngularDart英雄之旅教程抛出错误“英雄”不是函数吗?

[英]AngularDart tour of heroes tutorial throws an error 'Hero' isn't a function?

错误:“英雄”不是函数。 (位于[angular_dart_tour_of_heroes] lib \\ app_component.dart:18处的invocation_of_non_function)

英雄飞镖

class Hero {
  final int id;
  String name;

  Hero(this.id, this.name);
}

app_component.dart

import 'package:angular/angular.dart';
import 'package:angular_components/angular_components.dart';

import 'hero.dart';

@Component(
  selector: 'my-app',
  styleUrls: const ['app_component.css'],
  templateUrl: 'app_component.html',
  directives: const [materialDirectives,],
  providers: const [materialProviders],
)
class AppComponent {
  final title = 'Tour of Heroes';
  Hero hero = Hero(1, 'Windstorm');

}

app_component.html

<h1>{{title}}</h1>
<h2>{{hero.name}}</h2>
<div><label>id: </label>{{hero.id}}</div>
<div><label>name: </label>{{hero.name}}</div>

听起来您使用的Dart版本太旧,仍然需要new可选版本

似乎您在Dart 1下使用的是Angular 5 / Dart 2版本的教程。您正在使用哪个版本的Dart SDK? (运行: dart --version )。

我建议使用Angular 2和Dart 2

如果要使用Dart 1.24.3 ,则需要本教程Angular 4版本

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM