簡體   English   中英

@Input()值始終是打字稿中未定義的

[英]@Input() value is always undefined from typescript

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,

                }                
            ]
        }
    }

}

if(this.data)總是失敗,數據是不確定的,但是當從order-progressbar-dynamic.component.html使用它時,我確實得到了值。 如何使@Input值可從類方法中使用?

使用ngOnInit鈎子獲取@Input

constructor(private el: ElementRef) {}

ngOnInit() {
  this.generateDataForProgressbar();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM