I am trying to convert a number value to a string in angular 2 using typescript within a pipe. It complains
Type string is not assignable to type number
. My pipe is as follows.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'pxsuffix'
}) export class pxsuffix implements PipeTransform {
transform(input: number): number {
if ((input > 0)) {
input = input.toString(),
}
return (
input = input + 'px',
);
}
}
Your function is asking for returning a Number and you are returning a String. Try:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'pxsuffix'
}) export class pxsuffix implements PipeTransform {
transform(input: number): string{ //string type
return input + 'px';
} }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With