How to use pipes in logic (typescrit) code

I used to create custom filters with ionic 1 (angularjs) and then use them either in the template {{data | customfilter }} or in the controller str = $filter(‘customfilter’)(data);.

Now I just created a pipe with angular 2, but how to use it in the typescript code ?



import {Pipe} from '@angular/core';

  name: 'nospace'
export class Nospace {
  transform(value, args) {
    return (!value) ? '' : value.replace(/ /g, '');


import {Component} from '@angular/core';
import {Nospace} from '../../pipes/nospace';

  templateUrl: 'build/pages/home/home.html',
  pipes: [Nospace]
export class HomePage {

  myString: any;

  constructor() {
    this.myString = "Pipes are super cool";
    //I want to use the pipe here !

Lose pipes: [Nospace] and add Nospace to the declarations stanza of your app module.

Ok thanks, I am going to try this

Hi rapropos, how can we call Nospace pipe in controller level , html is like {{data | Nospace}} , same thing how can we do in controller level ,please help.


Just call that same replace on whatever the string is that you want to take the spaces out of.