简体   繁体   English

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

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

相关问题 Firebase在AngularDart项目中引发错误 - Firebase throws error in an AngularDart project PWA Worker使用AngularDart引发错误 - PWA Worker throws an error with AngularDart 构建失败-检查导入-Dart Angular教程-angular_tour_of_heroes-第2部分 - Build failed - Check imports - Dart Angular Tutorial - angular_tour_of_heroes - part 2 ScaffoldMessenger 抛出英雄 animation 错误 - ScaffoldMessenger throws a hero animation error Dart英雄角旅行2:大写 - Angular2 Tour of Heroes in Dart: uppercase 在 Flutter 中,VS Code 编辑器抛出错误 - 未定义函数“myApp” - In Flutter the VS Code editor throws an error - The function 'myApp' isn't defined 当&#39;items&#39;为null时,AngularDart筛选器调用方法将引发错误 - AngularDart Filter call method throws error when 'items' is null 路由Dart Angular Tour of Heroes时无法找到模块 - Unable to find modules when routing Dart Angular Tour of Heroes 在AngularDart中调用jQuery插件:不执行,没有错误,根本不起作用 - Calling jQuery plugin in AngularDart: no execution, no error, doesn't work at all angulardart firestore引发错误“ firebase.firestore不是函数” - angulardart firestore throw error “firebase.firestore is not a function”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM