53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { Component, Input } from '@angular/core';
|
|
import {ActivatedRoute} from '@angular/router';
|
|
import 'rxjs/Rx';
|
|
import {HelperService} from './helper.service';
|
|
import{EnvProperties} from '../properties/env-properties';
|
|
|
|
@Component({
|
|
selector: 'helper',
|
|
template: `
|
|
<div *ngIf=" texts && texts.length > 0" [ngClass]=styleName>
|
|
<div *ngFor="let text of texts " [innerHTML]="text.content">
|
|
</div>
|
|
</div>
|
|
`
|
|
})
|
|
export class HelperComponent {
|
|
texts=[];
|
|
@Input() style:boolean = false;
|
|
@Input() position:string = 'right';
|
|
@Input() styleName:string = '';
|
|
sub:any;
|
|
properties:EnvProperties;
|
|
|
|
constructor (private _service: HelperService, private route: ActivatedRoute,) {}
|
|
|
|
ngOnInit() {
|
|
this.route.data
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
this.properties = data.envSpecific;
|
|
|
|
if(this.properties.enableHelper && location){
|
|
this.sub = this._service.getHelper(location.pathname, this.properties).subscribe(
|
|
data => {
|
|
this.texts =(data && data.content && data.content[this.position] )? data.content[this.position]:[];
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
|
|
}
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
if(this.sub){
|
|
this.sub.unsubscribe();
|
|
}
|
|
}
|
|
|
|
|
|
}
|