gpt4 book ai didi

dart - AngularDart英雄之旅教程抛出错误 'Hero'不是函数吗?

转载 作者:行者123 更新时间:2023-12-03 04:04:29 24 4
gpt4 key购买 nike

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

英雄 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

关于dart - AngularDart英雄之旅教程抛出错误 'Hero'不是函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51388936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com