Created
March 29, 2014 11:08
-
-
Save rolaveric/9852538 to your computer and use it in GitHub Desktop.
Example of DI working in AngularDart.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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