JPNN
JPNN

Reputation: 403

In angular how to trim value in one way data binding

In angular how to trim value in one way data binding, and can we do it at component.html not in typescript ?like below but didn't work :

<P>{{country.trim()}}</P>

Thanks

Upvotes: 0

Views: 2146

Answers (1)

Minal Shah
Minal Shah

Reputation: 1486

you can use pipe for using the trim function in html only.

For pipe. please refer the following code:

@Pipe({ name: 'trimContent' })
export class TrimContent implements PipeTransform {

    transform(value: any) {
        if (value) {
            return value.trim();
        }
        return value;
    }

}

And now update your html code with the following line:

<P>{{country | trimContent}}</P>

Upvotes: 3

Related Questions