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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.