import {Component, OnInit, ChangeDetectionStrategy, ElementRef, Input} from '@angular/core';
import {FadeInTop} from "../../../../../shared/animations/fade-in-top.decorator";
declare var $: any;
@FadeInTop()
@Component({
selector: 'order-progressbar-dynamic',
templateUrl: 'order-progressbar-dynamic.component.html',
})
export class OrderProgressBarDynamicComponent {
@Input() public data: any;
public progressBar: {index: number, btnID: string, btnTag: string, title: string, status: boolean, statusTag: string, prevStepStatus: boolean}[];
constructor(private el: ElementRef) {
this.generateDataForProgressbar();
}
public generateDataForProgressbar() {
if (this.data) {
this.progressBar = [
{
"index": 0,
"btnID": "orderConfirmed",
"status": this.data.orderStatus.saleConfirmed,
},
{
"index": 1,
"btnID": "item",
"status": this.data.orderStatus.item,
}
]
}
}
}
如果(this.data)一直失败,数据是未定义的,但是当从order-progressbar-dynamic.component.html
使用时,我确实得到了值。如何使@Input值从类方法中可用?
答案 0 :(得分:3)
使用ngOnInit
挂钩获取@Input
值
constructor(private el: ElementRef) {}
ngOnInit() {
this.generateDataForProgressbar();
}