Last active
August 29, 2015 13:57
-
-
Save rolaveric/9850668 to your computer and use it in GitHub Desktop.
Simple example of a directive 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
import 'dart:html'; | |
import 'package:angular/angular.dart'; | |
// Annotation which states that this class is a directive which should be | |
// attached to elements with a 'sample-text-id' attribute | |
@NgDirective(selector: '[sample-text-id]') | |
class ReverseClickDirective{ | |
// The element that the directive is attached to | |
Element element; | |
// The class constructor which is called against the matching element | |
// Somewhat like the "link" method in AngularJS | |
ReverseClickDirective(this.element) { | |
element.onClick.listen(reverseText); | |
} | |
void reverseText(MouseEvent event) { | |
var text = element.text; | |
var buffer = new StringBuffer(); | |
for (int i = text.length - 1; i >= 0; i--) { | |
buffer.write(text[i]); | |
} | |
element.text = buffer.toString(); | |
} | |
} | |
void main() { | |
// Bootstrap the application with a module that includes our directive | |
ngBootstrap(module: new Module() | |
..type(ReverseClickDirective)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment