I\'m learning Angular2. I have a component with a variable which is an object. I\'m iterating over the fields of the object, and acording to the type of data of that positio
You can create simple pipe which will receive current item and return item type.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'typeof'
})
export class TypeofPipe implements PipeTransform {
transform(value: any): any {
console.log("Pipe works ",typeof value);
return typeof value;
}
}
Now you can use typeofpipe in html like this
*ngIf = (item | typeof) === 'number'"
And be careful in using function call in your html as mentioned above. It preferred to use pipe instead of function call. Here is Stackblitz example. In first case function call will triggered on any change detection (example on clicking on buttons).