File

projects/storefrontlib/cms-components/content/link/link.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-link
templateUrl ./link.component.html

Index

Properties
Methods
HostBindings

Constructor

constructor(component: CmsComponentData<CmsLinkComponent>)
Parameters :
Name Type Optional
component CmsComponentData<CmsLinkComponent> No

HostBindings

class
Type : string

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.

Parameters :
Name Type Optional
data CmsLinkComponent No
Returns : string | null

Properties

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
Component
Html element with directive

result-matching ""

    No results matching ""