@reibo/ngx-destroy
v0.0.1
Published
[](https://www.npmjs.com/package/%40reibo%2Fngx-destroy)  [
Usage on an angular component
Without implementing OnDestroy
import {Component} from '@angular/core';
import {interval} from 'rxjs';
import {map} from 'rxjs/operators';
import {Destroy, DestroyClass} from '@reibo/ngx-destroy'
@DestroyClass
@Component({
selector: 'app-destroy',
templateUrl: './destroy.component.html',
styleUrls: ['./destroy.component.css']
})
export class DestroyComponent {
@Destroy
stream$ = interval(1000).pipe(
map(() => `property ${new Date()}`),
);
@Destroy
getStreamTest() {
return interval(1000).pipe(
map(() => `function ${new Date()}`),
);
}
constructor() {
this.stream$.subscribe();
this.getStreamTest().subscribe(console.log);
}
}
With implementing OnDestroy
import {Component, OnDestroy} from '@angular/core';
import {interval} from 'rxjs';
import {map} from 'rxjs/operators';
import {Destroy, DestroyClass} from '@reibo/ngx-destroy'
@DestroyClass
@Component({
selector: 'app-destroy',
templateUrl: './destroy.component.html',
styleUrls: ['./destroy.component.css']
})
export class DestroyComponent implements OnDestroy {
@Destroy
stream$ = interval(1000).pipe(
map(() => `property ${new Date()}`),
);
@Destroy
getStreamTest() {
return interval(1000).pipe(
map(() => `function ${new Date()}`),
);
}
constructor() {
this.stream$.subscribe();
this.getStreamTest().subscribe(console.log);
}
ngOnDestroy() {
console.log('destroy')
}
}
