[英]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.