如何为每篇文章在Angular2上创建一个永久链接

时间:2017-03-28 19:45:19

标签: angular meteor permalinks angular2-meteor

我正在使用Meteor-Angular2开发博客格式

问题是我无法弄清楚如何为每篇文章(帖子)制作永久链接,尽管它有很好的数据库系统。

如何在Angular2应用程序上创建永久链接系统?

1 个答案:

答案 0 :(得分:0)

第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,'-')
    }
}

第2步将其添加到app.module.ts

declarations:[
             ... 
             permalinkPipe
             ]

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