Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 466f187

Browse files
committed
feat(demo): Very basic components
1 parent f1bb847 commit 466f187

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

demo/web/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ <h1>A Demo of the Bind Directive</h1>
1414
<h1>A Demo of the Repeat Directive</h1>
1515
<ul>
1616
<li ng-repeat="name in people" ng-bind="name"></li>
17+
<li ng-repeat="obj in objs" ng-bind="obj.v"></li>
1718
</ul>
1819

1920
<h1>A Demo of Components</h1>
20-
<div tabs>
21-
<div pane title="Pane 1">Pane 1 Contents</div>
22-
<div pane title="Pane 2">Pane 2 Contents</div>
21+
<div book>
22+
<div chapter title="The First Act">The contents of the first act.</div>
23+
<div chapter title="The Second Act">The contents of the second act.</div>
2324
</div>
2425
</div>
2526
</body>

demo/web/main.dart

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AngularBootstrap {
2121
return lastRandom;
2222
};
2323
$rootScope['people'] = ["James", "Misko"];
24+
$rootScope['objs'] = [{'v': 'v1'}, {'v': 'v2'}];
2425

2526
var template = $compile.call(topElt);
2627
template.call(topElt).attach($rootScope);
@@ -30,67 +31,68 @@ class AngularBootstrap {
3031
}
3132
}
3233

33-
class TabsController implements Controller {
34+
class BookController implements Controller {
3435
Scope $scope;
35-
List panes;
36-
var selectedPanes = new Expando<dom.Node>();
36+
List chapters;
3737

38-
MainController(Scope this.$scope) {
39-
panes = $scope.panes = [];
38+
BookController(Scope this.$scope) {
39+
$scope.greeting = "TabController";
40+
chapters = [];
41+
$scope.chapters = chapters;
4042

41-
$scope.selected = (pane) {
42-
panes.forEach((p) {
43-
selectedPanes[p]['selected'] = false;
43+
$scope.selected = (chapterScope) {
44+
chapters.forEach((p) {
45+
p["selected"] = false;
4446
});
45-
selectedPanes[pane]['selected'] = true;
47+
chapterScope["selected"] = true;
4648
};
4749
}
4850

49-
addPane(dom.Node pane) {
50-
if (panes.length == 0) { $scope.selected(pane); }
51-
panes.add(pane);
51+
addChapter(var chapterScope) {
52+
if (chapters.length == 0) { ($scope.selected)(chapterScope); }
53+
chapters.add(chapterScope);
5254
}
5355
}
5456

55-
class TabsAttrDirective {
56-
static var $transclude = "true";
57-
static String $template = '<div class="tabbable">Shadow' +
58-
'<ul class="nav nav-tabs">' +
59-
'<li ng-repeat="pane in panes" ng-class="{active:pane.selected}">'+
60-
'<a href="" ng-click="select(pane)">{{pane.title}}</a>' +
61-
'</li>' +
57+
class BookAttrDirective {
58+
static var $controller = BookController;
59+
static String $template =
60+
'<div>Shadow backed template. Greeting from the controller: <span ng-bind="greeting"></span>' +
61+
'<h2>Table of Contents</h2><ul class="nav nav-tabs">' +
62+
' <li ng-repeat="chapter in chapters" ng-bind="chapter.title"></li>' +
6263
'</ul>' +
63-
'<content class="tab-content" ng-transclude>CONTENT</content>' +
64+
'<content></content>' +
6465
'</div>';
65-
// static String $template = '<div>Hello shaddow</div>';
66-
BlockList blockList;
6766

67+
attach(Scope scope) {}
68+
}
6869

69-
TabsAttrDirective(BlockList this.blockList,
70-
dom.Element element) {
71-
dom.ShadowRoot shadow = element.createShadowRoot();
72-
73-
74-
print("tab attr: ${element.text}");
75-
print("shadow: ${shadow.text}");
76-
77-
}
70+
class ChapterAttrDirective {
71+
static var $require = "^[book]";
72+
BookController controller;
73+
dom.Element element;
74+
ChapterAttrDirective(dom.Element this.element, Controller this.controller);
7875

7976
attach(Scope scope) {
80-
print("tab attach");
77+
// automatic scope management isn't implemented yet.
78+
var child = scope.$new();
79+
child.title = element.attributes['title'];
80+
controller.addChapter(child);
8181
}
8282
}
8383

8484
main() {
8585
// Set up the Angular directives.
8686
var module = new Module();
87+
module.value(Expando, new Expando());
8788
angularModule(module);
8889
Injector injector = new Injector([module]);
8990
Directives directives = injector.get(Directives);
9091
directives.register(NgBindAttrDirective);
9192
directives.register(NgRepeatAttrDirective);
9293
directives.register(NgShadowDomAttrDirective);
93-
directives.register(TabsAttrDirective);
94+
directives.register(BookAttrDirective);
95+
directives.register(ChapterAttrDirective);
9496

9597
injector.get(AngularBootstrap)();
9698

lib/block.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,20 @@ class Block implements ElementWrapper {
209209
controllers[requiredController] = controller;
210210
}
211211

212-
var directive = injector.get(directiveType);
212+
var directive;
213+
try {
214+
215+
directive = injector.get(directiveType);
216+
} catch (e,s) {
217+
var msg;
218+
if (e is MirroredUncaughtExceptionError) {
219+
msg = e.exception_string + "\n ORIGINAL Stack trace:\n" + e.stacktrace.toString();
220+
} else {
221+
msg = "Creating $directiveName: " + e.toString();
222+
}
223+
224+
throw msg;
225+
}
213226
directives.add(directive);
214227
}
215228
}

0 commit comments

Comments
 (0)