【发布时间】:2019-03-07 00:55:50
【问题描述】:
我正在用 angular 7 和 angular material 构建一个电子应用程序
我有一个 Stepper,第二步调用 electron main 以使用户选择将保存应用程序内容的文件夹。 当它被选中时,它会调用“selectedWorkingFolder”,它将步骤设置为已完成,应该使用 (this.stepper.next()) 直接转到步骤 3,除非我单击窗口上的任何位置,否则这不起作用。
这是一个展示它的 gif 图像
https://i.gyazo.com/7e17510822bc7b3946bc6e917e965466.mp4
这是控制器代码
import { Component, OnInit, Input, ChangeDetectorRef, ViewChild } from '@angular/core';
import { ElectronService } from 'src/app/services/electron/electron.service';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.css']
})
export class MainComponent implements OnInit {
@ViewChild('stepper') stepper;
firstFormGroup: FormGroup;
secondFormGroup: FormGroup;
isLinear = true;
constructor(
private readonly ipcServ: ElectronService,
private cdRef: ChangeDetectorRef,
private _formBuilder: FormBuilder,
) {
this.firstFormGroup = this._formBuilder.group({
firstCtrl: ['', Validators.required]
});
this.secondFormGroup = this._formBuilder.group({
secondCtrl: ['', Validators.required]
});
this.ipcServ.on('databaseCheckResult', (event, docs) => {
console.log(docs);
this.changeState(docs);
});
this.ipcServ.on('selectedWorkingFolder', (event, docs) => {
this.stepper.selected.completed = true;
this.stepper.selected.editable = false;
this.stepper.next();
});
}
ngOnInit() {
this.ipcServ.send('checkdb');
}
changeState(action) {
if (action === 'unconfigured') {
this.cdRef.detectChanges();
} else {
}
}
stepperEvents(event) {
if (event.selectedIndex === 1) {
this.ipcServ.send('selectFolder');
}
}
}
这是html代码
<mat-vertical-stepper labelPosition="bottom" #stepper (selectionChange)="stepperEvents($event)">
<mat-step [stepControl]="firstFormGroup">
<form [formGroup]="firstFormGroup">
<ng-template matStepLabel>Enter your profile name</ng-template>
<mat-form-field>
<input matInput placeholder="Profile Name" formControlName="firstCtrl" required>
</mat-form-field>
<br>
</form>
</mat-step>
<mat-step [stepControl]="secondFormGroup">
<ng-template matStepLabel>Select the working folder</ng-template>
</mat-step>
<mat-step>
<ng-template matStepLabel>Done</ng-template>
You are now done.
</mat-step>
</mat-vertical-stepper>
而且我对 Angular 还是很陌生,所以任何关于如何改进我的代码的提示都会有很大帮助。
谢谢
【问题讨论】: