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 ?

Thanks

src/pipes/nospace.ts:

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

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

src/pages/page.ts:

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

@Component({
  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.

Thanks,
Hash57

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