Angular: The getter 'injector$Injector' isn't defined for the class 'self' reported by dart analyzer in VScode

Created on 13 Feb 2019  路  1Comment  路  Source: angulardart/angular

Environment:
Dart VM version: 2.1.1-dev.3.2 (Thu Jan 24 11:50:07 2019 +0100) on "macos_x64"
angular-5.2.0

Please check the two stackoverflow questions for detail:

Basically, vscode reports error message The getter 'injector$Injector' isn't defined for the class 'self' for the code in official tutorial:

@GenerateInjector(
  routerProvidersHash, // You can use routerProviders in production
)
final InjectorFactory injector = self.injector$Injector;

I was so confused when I first met this error when I follow the exact steps in official tutorial.

Btw, I am not sure where I should report this issue. Not sure if this should belong to dart? angular? dart analyzer? angular analyzer? vscode? angular document? But this is definitely an issue. Sorry that if I am reporting this in a wrong github project.

Most helpful comment

First of all, an error for that line is to be expected, until you've built the application at least once. The self refers to the imported library that is generated by AngularDart: import 'main.template.dart' as self;. Until the first build, this file doesn't yet exist, so the analyzer will complain about any references to it.

Once you've built your project (likely via webdev serve for development or webdev build for deployment), the main.template.dart file will be generated and that import will be valid.

If you're still seeing this error after you've rebuilt, you might need to restart the Dart analyzer. I'm not sure how to do this is VS Code, but restarting the IDE should work if there's no other way to do it.

Secondly, that is a very confusing error message, since self isn't a class, but rather a prefix on an imported library. I'll file an issue against the analyzer to see if this message in particular can be improved.

>All comments

First of all, an error for that line is to be expected, until you've built the application at least once. The self refers to the imported library that is generated by AngularDart: import 'main.template.dart' as self;. Until the first build, this file doesn't yet exist, so the analyzer will complain about any references to it.

Once you've built your project (likely via webdev serve for development or webdev build for deployment), the main.template.dart file will be generated and that import will be valid.

If you're still seeing this error after you've rebuilt, you might need to restart the Dart analyzer. I'm not sure how to do this is VS Code, but restarting the IDE should work if there's no other way to do it.

Secondly, that is a very confusing error message, since self isn't a class, but rather a prefix on an imported library. I'll file an issue against the analyzer to see if this message in particular can be improved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndreyChernykh picture AndreyChernykh  路  4Comments

ranquild picture ranquild  路  4Comments

ranquild picture ranquild  路  6Comments

chalin picture chalin  路  3Comments

matanlurey picture matanlurey  路  3Comments