Angular Dart提供了错误:未为类“ self”定义吸气剂“ injector $ Injector”

时间:2018-12-18 07:31:33

标签: dart angular-dart

我只是尝试在Angular Dart中进行路由。我正在遵循此https://webdev.dartlang.org/angular/guide/router/1指南,但出现错误。

此行显示错误final InjectorFactory injector = self.injector$Injector;,错误为The getter 'injector$Injector' isn't defined for the class 'self

import 'package:angular/angular.dart';
import 'package:angular_router/angular_router.dart';
import '../src/app_component.template.dart' as ng;

import 'main.template.dart' as self;

const useHashLS = false;
@GenerateInjector(routerProvidersHash)

final InjectorFactory injector = self.injector$Injector;
// The getter 'injector$Injector' isn't defined for the class 'self' 

void main() {
  runApp(ng.AppComponentNgFactory, createInjector: injector);
}

3 个答案:

答案 0 :(得分:2)

  

我遇到了同样的问题,因为它完整无误,我只是   在analysis_options.yaml上添加了以下内容,以忽略该错误。

analyzer:
  errors:
    undefined_getter: ignore

https://stackoverflow.com/a/53304768/2997534回答

答案 1 :(得分:0)

我认为这仅仅是因为@GenerateInjector注释不在注入器的正上方

答案 2 :(得分:0)

我偶然发现了一种解决方法,而没有忽略分析器:

import 'main.template.dart' show injector$Injector;

@GenerateInjector(routerProvidersHash)
final InjectorFactory injector = injector$Injector;

显示injector$Injector似乎可以解决该错误。