Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Unified Diff: third_party/pkg/angular/demo/web/main.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/demo/web/main.dart
diff --git a/third_party/pkg/angular/demo/web/main.dart b/third_party/pkg/angular/demo/web/main.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d9a1a606024e58709cbd0927c648eba530181b13
--- /dev/null
+++ b/third_party/pkg/angular/demo/web/main.dart
@@ -0,0 +1,82 @@
+import 'dart:html' as dom;
+import 'dart:math' as math;
+
+import 'package:angular/angular.dart';
+import 'package:di/di.dart';
+
+class BookController {
+ Scope $scope;
+ List chapters;
+
+ attach(Scope scope) {
+ $scope = scope;
+
+ $scope.greeting = 'TabController';
+ chapters = [];
+ $scope.chapters = chapters;
+
+ $scope.selected = (chapterScope) {
+ chapters.forEach((p) {
+ p['selected'] = false;
+ });
+ chapterScope['selected'] = true;
+ };
+ }
+
+ addChapter(var chapterScope) {
+ if (chapters.length == 0) { ($scope.selected)(chapterScope); }
+ chapters.add(chapterScope);
+ }
+}
+
+class BookComponent {
+ BookController controller;
+ BookComponent(BookController this.controller);
+
+ static String $templateUrl = 'book.html';
+ static String $cssUrl = 'book.css';
+
+ attach(Scope scope) {
+ controller.attach(scope);
+ }
+}
+
+class ChapterDirective {
+ BookController controller;
+ dom.Element element;
+ ChapterDirective(dom.Element this.element, BookController this.controller);
+
+ attach(Scope scope) {
+ // automatic scope management isn't implemented yet.
+ var child = scope.$new();
+ child.title = element.attributes['title'];
+ controller.addChapter(child);
+ }
+}
+
+@NgDirective(
+ selector: '[main-controller]'
+)
+class MainController {
+
+ String _random = 'Random: ${new math.Random().nextInt(100)}';
+
+ MainController(Scope scope) {
+ scope['greeting'] = 'Hello world!';
+ scope['people'] = ['James', 'Misko'];
+ scope['objs'] = [{'v': 'v1'}, {'v': 'v2'}];
+ scope['random'] = () {
+ return _random;
+ };
+ }
+}
+
+main() {
+ // Set up the Angular directives.
+ var module = new Module()
+ ..type(BookComponent)
+ ..type(ChapterDirective)
+ ..type(MainController);
+
+ ngBootstrap(module:module);
+}

Powered by Google App Engine
This is Rietveld 408576698