防止硬件后退按钮关闭android模态

时间:2020-01-30 10:30:23

标签: ionic-framework ionic4

我在Angular 8上使用Ionic 4 我想在按下android硬件的“后退”按钮时“禁用”模态关闭。

this.platform.backButton.subscribe(() => {
      console.log("Button Pressed");
    });

我可以跟踪事件,但是我不能阻止离子事件消除模态。

2 个答案:

答案 0 :(得分:0)

import { Component, ViewChild, ElementRef} from '@angular/core';
import { ApiService } from './api.service';
import { EventService} from './format-questions/format-questions.service'
import { FormGroup, FormBuilder, FormControl } from '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  questionForm: FormGroup;
  @ViewChild('closeBtn', {static: false}) closeBtn: ElementRef;
  data: any;
  questions: any[] = [];
  singleQuestion: any[] = [];

  constructor(private dataService:ApiService, private eventService:EventService, private formBuilder: FormBuilder) {
    this.questionForm = this.formBuilder.group({
      alrgyDetls: formBuilder.group({
        ALLERGY_DETAILS: ['']
      }),
      curntText :this.formBuilder.group({
        CURRENT_TEXT: ['']
      }),
      DosesForm :this.formBuilder.group({
        TEXT_NUMBER: [''],
        TEXT_DATE: ['']
      }),
    });
  }
// nextQuestion button logic for single question event
 getNextQuestion(e: any){
  let formattedQuestion = {};
  this.questions.shift();
  formattedQuestion = this.formatSubQuestions(e.answerOption.subQuestion);
  if(formattedQuestion){
    this.questionsArray.push(formattedQuestion);
    this.questionsOptionSelected = false;
  }
   if(this.questions.length > 0){
      this.singleQuestion = this.questions[0];
      if(this.questions.length === 1) {
        this.showNextButton = false;
        this.showSaveButton = true;
    }
  }    
 }
 onSubmit(){
    this.FormValues = this.questionForm.value;
    console.log("Form", this.FormValues.value);
 }


  // save changes and emit data to format component
 saveChanges(e:any){
  this.getNextQuestion(e);
  this.eventService.setData(this.questionsArray);
  this.questions = [];
  this.singleQuestion = [];
  this.questionsArray = [];
  this.closeBtn.nativeElement.click();
 }
}

答案 1 :(得分:0)

只需添加ModalOption backdropDismiss: false