Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - Number to String Conversion using pipe

Tags:

angular

pipe

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',

);
}
}
like image 668
user2182570 Avatar asked Dec 11 '22 12:12

user2182570


1 Answers

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';
} }
like image 181
ZanattMan Avatar answered Dec 13 '22 21:12

ZanattMan