How can I make a permalink at Angular2 for each article

431 Views Asked by At

I'm developing blog format using Meteor-Angular2

Problem is that I can't figure out how to make a permalink for each article(posts), though it has nice DB system.

How can I make a permalink system on Angular2 application?

1

There are 1 best solutions below

0
Muziki Ivan On

step 1 :first create a permalink pipe app.pipe.ts

@Pipe({name:'permalinkPipe',pure: false
})
@Injectable()


export class PermalinkPipe implements PipeTransform{


    transform(title:any):any{
        if (title==null) {
      return null;
    }
         return title.toLowerCase().trim().replace(/[\s]/g,'-')
    }
}

step 2 add it to the app.module.ts

declarations:[
             ... 
             permalinkPipe
             ]

step3 use it any where in your html.

[routerLink]="['/news', new.id,(new.title | permalinkPipe)]" //notice the brackets

<h1>{{title | permalinkPipe}}</h1>//this works
<h1>{{(title | permalinkPipe)}}</h1>//just link in the router link