THIS IS A REPOST OF https://stackoverflow.com/questions/45742971/ionic-can-i-navigate-through-a-pipe
I have a pipe to link and text with starts with a hash or an @ but navPush doesn’t seem to work. Can I navigate based on a condition in a pipe?
Here is my pipe where I would like to link normal text.
import {Injectable, Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'tags'
})
@Injectable()
export class TagsPipe implements PipeTransform {
// Pages
mePage = "MePage";
transform(value: string): string {
return value == undefined ? value : value
.replace(new RegExp('(#[A-Za-z0-9-_]+)', 'g'),'<a [navPush]="mePage" [navParams]="params" class="hashtag">$1</a>')
.replace(new RegExp('(@[A-Za-z0-9-_]+)', 'g'),'<a [navPush]="mePage" [navParams]="params" class="usertag">$1</a>');
}}
In this case “MePage” is a sample page which uses lazy loading and is already successfully loaded without any issue when not using a pipe.
Note that I tried to show the pipe using outer html (in my case <p [outerHTML]=“photo.desc | tags”>
) and the css classes show but [navPush] does not work. Also the injectable is there because I used ionic generate to create a new pipe