X Tutup
Skip to content

Commit 9d0d33f

Browse files
committed
feat(ngUpgrade): simple example
1 parent cf9d466 commit 9d0d33f

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library angualr2.playground.upgrade.index;
2+
3+
main() {
4+
// do nothing
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<html>
3+
<title>Angular Upgrade 2.0</title>
4+
<style>
5+
user {
6+
background-color: lightyellow;
7+
border: 2px solid darkorange;
8+
display: inline-block;
9+
width: 150px;
10+
padding: 1em;
11+
}
12+
</style>
13+
<body>
14+
<upgrade-app ng-controller="Index" [user]="name" (reset)="name=''">
15+
Your name: <input ng-model="name">
16+
<hr>
17+
<span class="greeting">Greetings from {{name}}!</span>
18+
</upgrade-app>
19+
<script src="/benchmarks_external/src/angular.js"></script>
20+
$SCRIPTS$
21+
</body>
22+
</html>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import {Component, Input, Output, EventEmitter} from 'angular2/angular2';
2+
import {UpgradeAdapter} from 'upgrade/upgrade';
3+
4+
var styles = [
5+
`
6+
.border {
7+
border: solid 2px DodgerBlue;
8+
}
9+
.title {
10+
background-color: LightSkyBlue;
11+
padding: .2em 1em;
12+
font-size: 1.2em;
13+
}
14+
.content {
15+
padding: 1em;
16+
}
17+
`
18+
];
19+
20+
var adapter: UpgradeAdapter = new UpgradeAdapter();
21+
22+
var ng1module = angular.module('myExample', []);
23+
24+
ng1module.controller('Index', function($scope) { $scope.name = 'World'; });
25+
26+
ng1module.directive('user', function() {
27+
return {
28+
scope: {handle: '@', reset: '&'},
29+
template: `
30+
User: {{handle}}
31+
<hr>
32+
<button ng-click="reset()">clear</button>`
33+
};
34+
});
35+
36+
@Component({
37+
selector: 'pane',
38+
template: `<div class="border">
39+
<div class="title">{{title}}</div>
40+
<div class="content"><ng-content></ng-content></div>
41+
</div>`,
42+
styles: styles
43+
})
44+
class Pane {
45+
@Input() title: string;
46+
}
47+
48+
49+
@Component({
50+
selector: 'upgrade-app',
51+
template: `<div class="border">
52+
<pane title="Title: {{user}}">
53+
<table cellpadding="3">
54+
<tr>
55+
<td><ng-content></ng-content></td>
56+
<td><user [handle]="user" (reset)="reset.next()"></user></td>
57+
</tr>
58+
</table>
59+
</pane>
60+
</div>`,
61+
styles: styles,
62+
directives: [Pane, adapter.upgradeNg1Component('user')]
63+
})
64+
class UpgradeApp {
65+
@Input() user: string;
66+
@Output() reset = new EventEmitter();
67+
constructor() {}
68+
}
69+
70+
ng1module.directive('upgradeApp', adapter.downgradeNg2Component(UpgradeApp));
71+
72+
export function main() {
73+
adapter.bootstrap(document.body, ['myExample']);
74+
}

tools/broccoli/html-replace/SCRIPTS.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
baseURL: '/',
66
packages: {
77
'angular2_material': {defaultExtension: 'js'},
8+
'upgrade': {defaultExtension: 'js'},
89
'benchmarks': {defaultExtension: 'js'},
910
'playground': {defaultExtension: 'js'},
1011
// TODO(rado): These helpers don't end up in the bundle, thus they should

tools/broccoli/trees/browser_tree.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const kServedPaths = [
5050
'playground/src/routing',
5151
'playground/src/sourcemap',
5252
'playground/src/todo',
53+
'playground/src/upgrade',
5354
'playground/src/zippy_component',
5455
'playground/src/async',
5556
'playground/src/material/button',

0 commit comments

Comments
 (0)
X Tutup