Skip to content

Instantly share code, notes, and snippets.

View stevermeister's full-sized avatar
🇺🇦

Stepan Suvorov stevermeister

🇺🇦
View GitHub Profile
export class TestComponent {
constructor(private route: ActivatedRoute, private router: Router) { }
ngOnInit() {
this.route.params.subscribe(console.log);
this.route.queryParams.subscribe(console.log);
this.route.fragment.subscribe(console.log);
this.route.data.subscribe(console.log);
this.route.url.subscribe(console.log);
export class TestComponent {
constructor(private renderer: Renderer2,
private element : ElementRef) { }
ngOnInit() {
this.clickSubscription = this.renderer.listen(this.element.nativeElement, "click", handler);
}
ngOnDestroy() {
this.clickSubscription.unsubscribe();
export class TestComponent {
constructor(private element : ElementRef) { }
interval: Subscription;
click: Subscription;
ngOnInit() {
this.intervalSubscription = Observable.interval(1000).subscribe(console.log);
this.clickSubscription = Observable.fromEvent(this.element.nativeElement, 'click').subscribe(console.log);
export class TestComponent {
constructor(private store: Store) { }
todos: Subscription;
ngOnInit() {
this.todosSubscription = this.store.select('todos').subscribe(console.log);
}
@Component({
selector: 'test',
template: `<todos [todos]="todos$ | async"></todos>`
})
export class TestComponent {
constructor(private store: Store) { }
ngOnInit() {
this.todos$ = this.store.select('todos');
export class TestDirective {
@HostListener('click')
onClick() {
....
}
}
export class TestComponent {
constructor(private http: Http) { }
ngOnInit() {
Observable.timer(1000).subscribe(console.log);
this.http.get('http://api.com').subscribe(console.log);
}
![]; // 'false'
!![]; // 'true'
[][[]]; // 'undefined'
![][1]; // 'a'
!![][0]; // 't'
[][[]][5]; // 'i'
@stevermeister
stevermeister / angular-component.ts
Created June 25, 2017 15:04
Example for Stepan Suvorov Blog
@Component({
selector: 'hello',
template: 'Hello!'
})
export class HelloComponent {}