简体   繁体   English

如何在每篇文章的Angular2上做一个永久链接

[英]How can I make a permalink at Angular2 for each article

I'm developing blog format using Meteor-Angular2 我正在使用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? 如何在Angular2应用程序上创建永久链接系统?

step 1 :first create a permalink pipe app.pipe.ts 步骤1:首先创建一个永久链接管道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 步骤2将其添加到app.module.ts

declarations:[
             ... 
             permalinkPipe
             ]

step3 use it any where in your html. step3在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM