问题打字稿执行顺序失败

时间:2018-12-17 14:58:51

标签: angular typescript

我正在调用一个函数来第一次从对象中保存一些数据,然后在第二次应用我的更改(使该对象为空),问题是我无法获取对象的内容

从模板调用函数:

<button class="btn btn-default myButton" (click)="onChangePartenaire()"
        [ngStyle]="!partenaireDisabled && {'background'  : 'gray'}">
        Creation
</button>

ngOnInit() {

 ............
 
this.apporteur = this.simulation.apporteur;

.............

}

onChangePartenaire() { console.log('this.apporteur',this.apporteur);
        this.partInitial = this.apporteur;
        this.partenaireDisabled = !this.partenaireDisabled;

        if(!this.partenaireDisabled) { //set this.apporteur to this.partInitial before and continue
            this.apporteur.simulation_info_apporteur_nom = '';
            this.apporteur.simulation_info_vendeur.simulation_info_vendeur_nom = '';
            this.apporteur.simulation_info_vendeur.simulation_info_vendeur_prenom = '';
            this.apporteur.simulation_info_vendeur.simulation_info_vendeur_email = '';
            this.apporteur.simulation_info_vendeur.simulation_info_vendeur_tel = '';
        } else {
            this.apporteur = this.partInitial;
        }

    }

我尝试了这个,但没有结果:

onChangePartenaire() { console.log('this.apporteur',this.apporteur);
        this.partInitial = this.apporteur;
        this.partenaireDisabled = !this.partenaireDisabled;

        let _this = this;
        setTimeout( function () {
            if(!_this.partenaireDisabled) {
                _this.apporteur.simulation_info_apporteur_nom = '';
                _this.apporteur.simulation_info_vendeur.simulation_info_vendeur_nom = '';
                _this.apporteur.simulation_info_vendeur.simulation_info_vendeur_prenom = '';
                _this.apporteur.simulation_info_vendeur.simulation_info_vendeur_email = '';
                _this.apporteur.simulation_info_vendeur.simulation_info_vendeur_tel = '';
            } else {
                _this.apporteur = _this.partInitial;
            }
        }, 100);


    }

感谢您的帮助。

0 个答案:

没有答案