File
Metadata
| changeDetection |
ChangeDetectionStrategy.OnPush |
| selector |
cx-link |
| templateUrl |
./link.component.html |
Index
Properties
|
|
|
Methods
|
|
|
HostBindings
|
|
|
Methods
|
getTarget
|
getTarget(data: CmsLinkComponent)
|
|
|
Returns _blank to force opening the link in a new window whenever the
data.target flag is set to true.
Returns : string | null
|
|
data$
|
Type : Observable<CmsLinkComponent>
|
Default value : this.component.data$.pipe(
tap((data) => (this.styleClasses = data?.styleClasses))
)
|
|
|
|
styleClasses
|
Type : string
|
Decorators :
@HostBinding('class')
|
|
|
import { ChangeDetectionStrategy, Component, HostBinding } from '@angular/core';
import { CmsLinkComponent } from '@spartacus/core';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { CmsComponentData } from '../../../cms-structure/page/model/cms-component-data';
@Component({
selector: 'cx-link',
templateUrl: './link.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LinkComponent {
@HostBinding('class') styleClasses: string;
data$: Observable<CmsLinkComponent> = this.component.data$.pipe(
tap((data) => (this.styleClasses = data?.styleClasses))
);
constructor(protected component: CmsComponentData<CmsLinkComponent>) {}
/**
* Returns `_blank` to force opening the link in a new window whenever the
* `data.target` flag is set to `true`.
*/
getTarget(data: CmsLinkComponent): string | null {
return data.target === 'true' || data.target === true ? '_blank' : null;
}
}
<cx-generic-link
*ngIf="data$ | async as data"
[url]="data.url"
[style]="data.styleAttributes"
[target]="getTarget(data)"
>{{ data.linkName }}</cx-generic-link
>
Legend
Html element with directive