| OLD | NEW |
| (Empty) |
| 1 import 'dart:html' as dom; | |
| 2 import 'dart:math' as math; | |
| 3 | |
| 4 import 'package:angular/angular.dart'; | |
| 5 import 'package:di/di.dart'; | |
| 6 | |
| 7 class BookController { | |
| 8 Scope $scope; | |
| 9 List chapters; | |
| 10 | |
| 11 attach(Scope scope) { | |
| 12 $scope = scope; | |
| 13 | |
| 14 $scope.greeting = 'TabController'; | |
| 15 chapters = []; | |
| 16 $scope.chapters = chapters; | |
| 17 | |
| 18 $scope.selected = (chapterScope) { | |
| 19 chapters.forEach((p) { | |
| 20 p['selected'] = false; | |
| 21 }); | |
| 22 chapterScope['selected'] = true; | |
| 23 }; | |
| 24 } | |
| 25 | |
| 26 addChapter(var chapterScope) { | |
| 27 if (chapters.length == 0) { ($scope.selected)(chapterScope); } | |
| 28 chapters.add(chapterScope); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 class BookComponent { | |
| 33 BookController controller; | |
| 34 BookComponent(BookController this.controller); | |
| 35 | |
| 36 static String $templateUrl = 'book.html'; | |
| 37 static String $cssUrl = 'book.css'; | |
| 38 | |
| 39 attach(Scope scope) { | |
| 40 controller.attach(scope); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 class ChapterDirective { | |
| 45 BookController controller; | |
| 46 dom.Element element; | |
| 47 ChapterDirective(dom.Element this.element, BookController this.controller); | |
| 48 | |
| 49 attach(Scope scope) { | |
| 50 // automatic scope management isn't implemented yet. | |
| 51 var child = scope.$new(); | |
| 52 child.title = element.attributes['title']; | |
| 53 controller.addChapter(child); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 @NgDirective( | |
| 58 selector: '[main-controller]' | |
| 59 ) | |
| 60 class MainController { | |
| 61 | |
| 62 String _random = 'Random: ${new math.Random().nextInt(100)}'; | |
| 63 | |
| 64 MainController(Scope scope) { | |
| 65 scope['greeting'] = 'Hello world!'; | |
| 66 scope['people'] = ['James', 'Misko']; | |
| 67 scope['objs'] = [{'v': 'v1'}, {'v': 'v2'}]; | |
| 68 scope['random'] = () { | |
| 69 return _random; | |
| 70 }; | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 main() { | |
| 75 // Set up the Angular directives. | |
| 76 var module = new Module() | |
| 77 ..type(BookComponent) | |
| 78 ..type(ChapterDirective) | |
| 79 ..type(MainController); | |
| 80 | |
| 81 ngBootstrap(module:module); | |
| 82 } | |
| OLD | NEW |