Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade existing custom angular Filter using upgrade module

I am using angular's upgrade module to create a hybrid app where both angular js and angular2 can co-exist together.I have a situation here where i need a existing custom filter to be used for a component.Does the upgrade module support upgrading custom filters.Ifsd so please advice how to do that?

like image 599
Thi49 Avatar asked Jan 18 '26 10:01

Thi49


1 Answers

Unfortunately upgrade module doesn't support upgrading filters to Pipes. But Pipes are very similar to filters and are really easy to upgrade manually.

If you need to have co-existing filter & Pipe I suggest to extract all logic & transforms to simple TypeScript / JavaScript:

export class PipeUtils {
    static myFilterTransform(value, ...args) {
        // return transformed value
    }
}

AngularJS filter:

angular.module('app', [])
.filter('myFilter', () => PipeUtils.myFilterTransform)

Angular Pipe:

export class MyPipe {
    transform(value, ...args) {
        return PipeUtils.myFilterTransform(value, ...args)
    }
}
like image 162
Anton Temchenko Avatar answered Jan 21 '26 01:01

Anton Temchenko