[英]AngularDart tour of heroes tutorial throws an error 'Hero' isn't a function?
error: 'Hero' isn't a function. 错误:“英雄”不是函数。 (invocation_of_non_function at [angular_dart_tour_of_heroes] lib\\app_component.dart:18)
(位于[angular_dart_tour_of_heroes] lib \\ app_component.dart:18处的invocation_of_non_function)
hero.dart 英雄飞镖
class Hero {
final int id;
String name;
Hero(this.id, this.name);
}
app_component.dart 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 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
可选版本
It seems like you are using a Angular 5 / Dart 2 version of the tutorial under Dart 1. Which version of the Dart SDK are you using? 似乎您在Dart 1下使用的是Angular 5 / Dart 2版本的教程。您正在使用哪个版本的Dart SDK? (Run:
dart --version
). (运行:
dart --version
)。
I'd suggest using Angular 2 and Dart 2 . 我建议使用Angular 2和Dart 2 。
If you want to use Dart 1.24.3 , then you'll need the Angular 4 version of the tutorial . 如果要使用Dart 1.24.3 ,则需要本教程的Angular 4版本 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.