File
Implements
Metadata
changeDetection |
ChangeDetectionStrategy.OnPush |
selector |
div[page-detail-horizontal-header] |
styleUrls |
./page-detail-horizontal-header.component.scss |
templateUrl |
./page-detail-horizontal-header.component.html |
Index
Properties
|
|
Methods
|
|
Inputs
|
|
HostBindings
|
|
Methods
Public
jsonToLogo
|
jsonToLogo(json)
|
|
|
import { Component, OnInit, Input, ChangeDetectionStrategy, HostBinding, Host, Inject } from '@angular/core';
import { UtilService } from 'src/app/core/services/util-service/util.service';
import { Title } from '@angular/platform-browser';
import { DOCUMENT } from '@angular/common';
interface Logo {
altText: string;
url: string;
}
@Component({
selector: 'div[page-detail-horizontal-header]',
templateUrl: './page-detail-horizontal-header.component.html',
styleUrls: ['./page-detail-horizontal-header.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class PageDetailHorizontalHeaderComponent implements OnInit {
@Input() entity;
@Input() region;
public h1: string;
public logos;
@HostBinding('class') get class() { return 'col-md-12'; }
constructor(private util: UtilService, private titleService: Title, @Inject(DOCUMENT) private document) { }
ngOnInit() {
this.titleService.setTitle(this.util.extract(this.entity, 'BrowserTabTitle') || 'SKF.com');
this.h1 = this.util.extract(this.entity, 'H1Title') || '';
// Consider only first four logos
this.logos = (this.util.extract(this.entity, 'Logo') || []).slice(0, 4).map(e => this.jsonToLogo(e));
// Add meta data tags to DOM head.
const metaTags = this.util.extract(this.entity, 'MetaTag') || [];
metaTags.forEach(metaTag => {
const tagName = this.util.extract(metaTag, 'MetaName');
const tagValue = this.util.extract(metaTag, 'MetaTag');
if (tagName && tagValue) {
const meta = this.document.createElement('meta');
meta.name = tagName;
meta.content = tagValue;
this.document.getElementsByTagName('head')[0].appendChild(meta);
}
});
}
public jsonToLogo(json): Logo {
const url = this.util.extract(json, 'Url') || '';
const altText = this.util.extract(json, 'Assetmetadata', 'Cmsdescription') || '';
const logo: Logo = {
altText: altText,
url: url
};
return logo;
}
}
<div class="row flex-wrap-reverse">
<div class="col-sm-12 col-md-5 d-flex justify-content-md-left align-self-center" *ngIf="logos.length > 0">
<div class="spacer" *ngFor="let logo of logos">
<img [src]="logo.url" [alt]="logo.altText">
</div>
</div>
<div class="col-sm-12 col-md-7" [ngClass]="{'h1-white': region === 'TOP',
'offset-md-5': logos.length === 0,
'title': true}" *ngIf="h1">
<h1 [innerHtml]="h1"></h1>
</div>
</div>
@import "src/app/styles/helpers";
.spacer {
img {
max-width: 100%;
max-height: calc-rem(100);
& + img {
margin-left: calc-rem(15);
}
}
}
.h1-white {
h1 {
color: white;
}
}
h1 {
color: $cool-grey;
margin-top: calc-rem(36);
}
Legend
Html element with directive