I am working on an Ionic2 app. Now, I am trying to implement a custom pipe; however, I receive the following error when doing so:
Uncaught TypeError: (0 , _ionicAngular.Pipe) is not a function
So far, here is my code:
import {Page, Pipe, NavController, NavParams} from 'ionic-angular';
//Phone formatting pipe
@Pipe({
name: 'phone'
})
export class PhonePipe{
transform(val, args) {
val = val.charAt(0) != 0 ? '0' + val : '' + val;
let newStr = '';
for(i=0; i < (Math.floor(val.length/2) - 1); i++){
newStr = newStr+ val.substr(i*2, 2) + '-';
console.log(val);
}
return newStr+ val.substr(i*2);
}
}
/////
@Page({
templateUrl: 'build/pages/outlet/outlet.html',
pipes: [PhonePipe]
})
export class place {
static get parameters() {
return [[NavController],[NavParams]];
}
constructor(nav, navParams) {
}
}
outlet.html
<ion-content id="contentPadding" padding class="outlet">
<div class="box">
<div class="bigTitle">{{outletPhoneValue | phone}}</div>
</div>
</ion-content>
When trying to implement Pipe in the following way:
import {Pipe} from 'angular2/core';
The first error disappear; however, a second error appears:
EXCEPTION: TypeError: val.charAt is not a function in [{{outletPhoneValue | phone}} in place@28:25]
Any idea on what's causing the error?
The Pipe
class must be imported from angular2/core
and not ionic-angular
:
import {Pipe} from 'angular2/core';