Last active
December 2, 2017 10:19
-
-
Save AndrewAllison/2e8984a5dac142261511aee9dd5d5439 to your computer and use it in GitHub Desktop.
RXJS using Take while
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { enableProdMode } from '@angular/core'; | |
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | |
import { AppModule } from './app/app.module'; | |
import { environment } from './environments/environment'; | |
// Common rxjs operators | |
import 'rxjs/add/operator/takeWhile'; | |
if (environment.production) { | |
enableProdMode(); | |
} | |
platformBrowserDynamic().bootstrapModule(AppModule); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, OnDestroy } from '@angular/core'; | |
import { SearchCriteriaService } from 'app/search/main/search-panel/search-criteria.service'; | |
import { SearchCriteria } from 'app/search/types/search-criteria.type'; | |
import { Subscription } from 'rxjs/Subscription'; | |
//import 'rxjs/add/operator/takeWhile'; | |
@Component({ | |
selector: 'app-search-panel-criteria', | |
templateUrl: './search-panel-criteria.component.html', | |
styleUrls: ['./search-panel-criteria.component.scss'] | |
}) | |
export class SearchPanelCriteriaComponent implements OnDestroy, OnInit { | |
isActive = true; | |
searchCriteria = []; | |
constructor(public searchCriteriaService: SearchCriteriaService) { } | |
ngOnInit() { | |
this.searchCriteriaService.items$ | |
.takeWhile(() => this.isActive) | |
.subscribe((searchCriteria: SearchCriteria[]) => { | |
this.searchCriteria = searchCriteria; | |
}); | |
} | |
onRemoveClicked(criteria: SearchCriteria) { | |
this.searchCriteriaService.removeItem(criteria); | |
} | |
ngOnDestroy() { | |
this.isActive = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment