簡體   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