Skip to content

Commit e3af5c0

Browse files
committed
(#6) Auto focus public directive
1 parent ace9ec8 commit e3af5c0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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)