Skip to content

Instantly share code, notes, and snippets.

@rolaveric
Created March 29, 2014 11:08
Show Gist options
  • Save rolaveric/9852538 to your computer and use it in GitHub Desktop.
Save rolaveric/9852538 to your computer and use it in GitHub Desktop.
Example of DI working in AngularDart.
// Simple class holding some configuration
class ConfigService{
String text;
ConfigService() {
this.text = "Meep!";
}
}
@NgDirective(selector: '[sample-text-id]')
class ReverseClickDirective{
// Second parameter is of type 'ConfigService', so the DI framework knows how to inject it
ReverseClickDirective(this.element, ConfigService config) {
element.text = config.text;
element.onClick.listen(reverseText);
}
// ...
}
void main() {
// Include "ConfigService" in the DI module
ngBootstrap(module: new Module()
..type(ReverseClickDirective)
..type(ConfigService));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment