繁体   English   中英

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

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

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

问题是,尽管它具有不错的数据库系统,但我不知道如何为每个文章(帖子)建立一个永久链接。

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

步骤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

暂无
暂无

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

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