Use RegExp to test if the url starts with http:
Add a getter to wrap the condition
Template
<a href="{{ object.Url}}"
newWindow Name="{{ object.Name }}" [isExternalLink]={{ isExternal }} >
{{object.Name}} </a>
Component class:
export class MyComponent {
get isExternal(): boolean {
// If you want to test https too: use /^https?:/ instead
return /^http:/.test(this.object.Url)
}
// ...
}
Alternative:
If you don't want to deal with regexp, use the String method startsWith
get isExternal(): boolean {
return this.object.Url.startsWith('http:')
}
Update:
If you want to make it inline:
<a href="{{ object.Url}}"
newWindow Name="{{ object.Name }}" [isExternalLink]={{ object.Url.startsWith('http:') }} >
{{object.Name}} </a>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…