src/app/pipes/linkinze.pipe.ts
| Name | linkinze |
No results matching.
Methods |
| transform | ||||||||
transform(path: string)
|
||||||||
|
Defined in src/app/pipes/linkinze.pipe.ts:13
|
||||||||
|
It makes path/url to be clicklable
Parameters :
Returns :
string
string to be used in |
import { Pipe, PipeTransform } from '@angular/core'
@Pipe({
name: 'linkinze',
standalone: false
})
export class LinkinzePipe implements PipeTransform {
/**
* It makes path/url to be clicklable
* @param path /example/path
* @returns string to be used in `innerHTML`
*/
transform(path: string): string {
if (!path.includes('/')) return path
let cascadingPath = ''
const pathSplit = path.split('/')
for (let i = 0; i < pathSplit.length; i++) {
if (pathSplit[i] !== '') {
const link = pathSplit[i]
cascadingPath += '/' + link
pathSplit[i] = `<a href=${cascadingPath}>${link}</a>`
}
}
return pathSplit.join('/')
}
}