Angular Dart is giving error : The getter 'injector$Injector' isn't defined for the class 'self'

Viewed 933

I am just trying Routing in Angular Dart. I was following this https://webdev.dartlang.org/angular/guide/router/1 guide but I am getting an error.

This line is giving error final InjectorFactory injector = self.injector$Injector; and the error is 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);
}
4 Answers

I was having the same problem, as it complete with no errors, I just added the following on analysis_options.yaml to ignore the error.

analyzer:
  errors:
    undefined_getter: ignore

Answer by https://stackoverflow.com/a/53304768/2997534

I stumbled upon a workaround without ignoring the analyzer:

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

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

Showing the injector$Injector seems to fix the error.

This can be fixed by restarting the app. If your app is running then stop it and restart using the command webdev serve. For more information you can refer here

I think it is just because the @GenerateInjector annotation is not directly above the injector

Related