Skip to content

Commit d41189d

Browse files
committed
Merge pull request #7 from opiepj/feature/6-homecomponent
Feature/6 homecomponent
2 parents 40d4122 + e3af5c0 commit d41189d

File tree

10 files changed

+1222
-0
lines changed

10 files changed

+1222
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,8 @@ then
5858
$ npm rune e2e
5959
```
6060

61+
# Angular 2.0 API
62+
reference: https://angular.io/docs/js/latest/api/
63+
6164
# License
6265
[MIT](/LICENSE)

src/app/components/home/home.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference path="../../../typings/_custom.d.ts" />
2+
3+
/*
4+
* Angular 2
5+
* @Component: factory function
6+
* @View: factory function
7+
* @ViewEncapsulation: ENUM How the template and styles of a view should be encapsulated.
8+
*/
9+
import {Component, View, ViewEncapsulation} from 'angular2/angular2';
10+
11+
/*
12+
* Directives
13+
* @angularDirectives: Angular's core/form/router directives
14+
* @appDirectives: Our collection of directives from /directives
15+
*/
16+
import {appDirectives, angularDirectives} from 'app/directives/directives';
17+
18+
// Webpack's `require` to get files
19+
let styles = require('./styles/home.css');
20+
let template = require('./views/home.html');
21+
22+
// Simple external file component example
23+
@Component({
24+
selector: 'home'
25+
})
26+
@View({
27+
directives: [ angularDirectives, appDirectives ],
28+
encapsulation: ViewEncapsulation.EMULATED, // EMULATED: Emulate scoping of styles by preprocessing the style rules and adding additional attributes to elements.
29+
// include .html and .css file
30+
styles: [ styles ],
31+
template: template
32+
})
33+
export class Home {
34+
constructor() {
35+
36+
}
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.home {
2+
background-color: #F8F8F8;
3+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path="../../../../typings/_custom.d.ts" />
2+
import {Component, View} from 'angular2/angular2';
3+
import {Home} from './home';
4+
5+
@Component({
6+
selector: 'test-cmp'
7+
})
8+
@View({
9+
directives: [ Home ]
10+
})
11+
class TestComponent {
12+
13+
}
14+
15+
describe('Home', () => {
16+
var home;
17+
18+
beforeEach(() => {
19+
home = new Home();
20+
});
21+
22+
it('should work', () => {
23+
expect(home).toBeDefined();
24+
});
25+
26+
});
27+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="home">
2+
<h2>Home</h2>
3+
</div>

src/app/directives/directives.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/// <reference path="../../typings/_custom.d.ts" />
22
/*
33
* Angular 2
4+
* @coreDirectives: collection of Angular core directives
5+
* @formDirectives: list of all the form directives
6+
* @routerDirectives: list of all the router directives
47
*/
58
import {coreDirectives, formDirectives} from 'angular2/angular2';
69
import {routerDirectives} from 'angular2/router';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="../../../typings/_custom.d.ts" />
2+
/*
3+
* Angular 2
4+
* @Directive: factory function
5+
* @ElementRef: class, reference to the element
6+
*/
7+
import {Directive, ElementRef} from 'angular2/angular2';
8+
// Simple example directive that fixes autofocus problem with multiple views
9+
@Directive({
10+
selector: '[autofocus]' // using [ ] means selecting attributes
11+
})
12+
export class Autofocus {
13+
constructor(public el: ElementRef) {
14+
// autofocus fix for multiple views
15+
if (this.el.nativeElement.focus) {
16+
this.el.nativeElement.focus();
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)