//set id if present
this.route.queryParams
.pipe(
map(param => param['id'])
)
.subscribe(paramValue => {
this.contractId = paramValue;
});
The same way I need to check for applicationId
var idQueryParamObs = this.route.queryParams
.pipe(
filter(param => param['id'] != null),
map(param => param['id'])
);
var applicationIdQueryParamObs = this.route.queryParams
.pipe(
filter(param => param[applicationId'] != null),
map(param => param['applicationId'])
);
Connecting to dev server
at the bottom after I hit Run this project button.
ngOnInit() {
this.id$ = this.route.queryParams.pipe(map(params => params.id)); //<---- why no filter here
this.applicationId$ = this.route.queryParams.pipe(
filter(params => !!params.appId), //<----- but here any intended purpose of this?
map(params => params.appId)
);
const combinedIds$ = combineLatest([
this.id$.pipe(filter((id: string) => id !== null)), // and then here
this.applicationId$.pipe(
filter((applicationId: string) => applicationId !== null)
)
]);
this.result$ = combinedIds$.pipe(
map(([id, applicationId]: [string, string]) => ({
id,
applicationId
}))
);
this.result$.subscribe(result => {
console.log({ result });
});
}
}
Project
function it expects. I am never able to implement it.
//set id if present
var idParam = this.route.queryParams
.pipe(
filter(params => !!params.id),
map(params => params.id)
);
var applicationParam = this.route.queryParams
.pipe(
filter(params => !!params.applicationId),
map(params => params.applicationId)
);
const combined = combineLatest([
idParam.pipe(filter((id: string) => id !== null)),
applicationParam.pipe(
filter((applicationId: string) => applicationId !== null)
)
]).pipe(
map(([id, applicationId] : [string, string]) => ({
id,
applicationId
}))
);
var result = combined.pipe(
switchMap(result => {
})
);
result.subscribe((contract: TenantContract) => {
});
I am getting an error in switchMap clause.
this.apiService
.getVigencia()
.pipe(
tap(() => this.getUserSuscriptions()),
filter(res => res.vigenciaIva != true)
)
.subscribe( // do something)
.......
// the function getUserSubcription() is his own best
getUserSuscriptions() {
this.apiService
.getStatus(requestData, this.userRut)
.pipe(
tap(res => {
this.showError =
Array.isArray(res.servicios) && res.servicios.length === 0;
}),
filter(() => this.showError === false)
)
.subscribe(
// process the everything
)
This is legacy code, but i would like to change using concatMap to call in sequence . I having issues with this for some weird cases.
this.apiService.getVigencia().pipe(
mergeMap( data => this.apiService.getStatus( requestData, this.userRut ) )
.pipe(
filter( res => res.vigenciaIva !== true ),
map( res => ( [data, res] )
).subscribe(
finalData => {
console.log(finalData);
},
error => {
this.showError = error
}
);
Hi there, I have this three methods:
getDateRange($event) {
this.dateRange = $event.range;
}
getMembers($event) {
this.highlightMembers = $event.selectedMembers;
}
isChecked($event) {
reurn this.statusSelected.concat(this.prioritySelected)
}
I need to create an array from combination of all of this events, because at last I need to send an eventEmitter that contains this array created dynamically from those events, there is a way to do this with rxjs?
@SAGOlab Although I'd create a type definition for the object:
export interface EmitterType {
range: string; // or number or whatever
selectedMembers: Member[];
isChecked: boolean;
}
...
@Output someEventEmitter: EventEmitter<EmitterType> = new EventEmitter<EmitterType>();
...
someEventEmitter.emit({range: $event.range,
selectedMembers :$event.selectedMembers,
isChecked: this.statusSelected.concat(this.prioritySelected),
});
...assuming I've correctly understood what you're asking.
isChecked($event) {
if ($event.selectedMembers !== undefined) {
this.highlightMembers = ;
this.highlightMembers.forEach(member => this.statusSelected.push(member))
const withMembers = this.statusSelected.concat(this.prioritySelected);
this.toggleCheck.emit({$event, optionsChecked: withMembers});
}
else if ($event.range !== undefined) {
this.dateRange = $event.range;
this.statusSelected.push(this.dateRange)
this.highlightMembers.forEach(member => this.statusSelected.push(member))
const withDate = this.statusSelected.concat(this.prioritySelected);
this.toggleCheck.emit({$event, optionsChecked: withDate});
}
else {
const withoutMembers = this.statusSelected.concat(this.prioritySelected)
this.toggleCheck.emit({$event, optionsChecked: withoutMembers});
}
this.toggleCheck.emit({$event, optionsChecked: b});
$event
in memory and combine them populating a unique array dynamically with or without the checkboxes selected or whatever else
import { Component, EventEmitter, Output, ViewChild, ViewEncapsulation } from '@angular/core';
import { MatSelectionList } from '@angular/material/list';
@Component({
selector: 'app-tasks-columns-menu',
templateUrl: './tasks-columns-menu.component.html',
styleUrls: ['./tasks-columns-menu.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class TasksColumnsMenuComponent {
@ViewChild('priority', {static: true}) priority: MatSelectionList;
@ViewChild('states', {static: true}) states: MatSelectionList;
prioritySelected: object[] = [];
statusSelected: object[] = [];
highlightMembers: object[] = [];
dateRange: object = [];
mergeOptionsChecked: object[] = [];
removable: boolean = true;
@Output() toggleCheck = new EventEmitter<{$event: any, optionsChecked: object}>();
@Output() userSelected = new EventEmitter<{$event: any, user: object[]}>();
statusLabels: object[] = [
{
label: 'In attesa',
status: 'Ready',
key: 'task-status'
},
{
label: 'Preso in carico',
status: 'Reserved',
key: 'task-status'
},
{
label: 'In lavorazione',
status: 'InProgress',
key: 'task-status'
},
{
label: 'Sospeso',
status: 'Suspended',
key: 'task-status'
}];
priorityLabels: object[] = [
{
label: 'Bassa',
priority: [0, 1, 2, 3],
key: 'task-priority'
},
{
label: 'Media',
priority: [4, 5, 6, 7],
key: 'task-priority'
},
{
label: 'Alta',
priority: [8, 9, 10],
key: 'task-priority'
}
]
constructor() {}
stopPropagation($event) {
$event.stopPropagation();
}
isChecked($event) {
if ($event.selectedMembers !== undefined) {
this.highlightMembers = $event.selectedMembers;
this.highlightMembers.forEach(member => this.statusSelected.push(member))
const withMembers = this.statusSelected.concat(this.prioritySelected);
this.toggleCheck.emit({$event, optionsChecked: withMembers});
}
else if ($event.range !== undefined) {
this.dateRange = $event.range;
this.statusSelected.push(this.dateRange)
this.highlightMembers.forEach(member => this.statusSelected.push(member))
const withDate = this.statusSelected.concat(this.prioritySelected);
this.toggleCheck.emit({$event, optionsChecked: withDate});
}
else {
const withoutMembers = this.statusSelected.concat(this.prioritySelected)
this.toggleCheck.emit({$event, optionsChecked: withoutMembers});
}
}
remove($event, member: object): void {
const index = this.highlightMembers.indexOf(member);
if (index >= 0) this.highlightMembers.splice(index, 1);
const removeMembers = this.mergeOptionsChecked.filter(option => option['label'] !== member['label'])
this.toggleCheck.emit({$event, optionsChecked: removeMembers});
}
}