error: 'Hero' isn't a function. (invocation_of_non_function at [angular_dart_tour_of_heroes] lib\\app_component.dart:18)
hero.dart
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
可选版本
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? (Run: dart --version
).
I'd suggest using Angular 2 and Dart 2 .
If you want to use Dart 1.24.3 , then you'll need the Angular 4 version of the tutorial .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.