4

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

);
}
}

1 Answer 1

14

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';
} }
Sign up to request clarification or add additional context in comments.

1 Comment

Can you please accept the answer and up vote it so other people can use it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.