在Angular 4中使用ngx bootstrap没有关闭popup

时间:2017-08-11 02:51:50

标签: angular

当我使用来自UI的邮政编码搜索任何位置时,iam使用弹出窗口向用户显示后端搜索过程正在进行。为此我创建了一个服务来打开和关闭弹出窗口。搜索服务搜索位置之前,我能够创建弹出窗口。如何完成搜索弹出窗口没有关闭。下面是我使用的代码。

import { Injectable,Component,OnInit,ViewChild, ElementRef,TemplateRef  } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/modal-options.class';

@Injectable()
export class **LoadingIndicatorService** {

  bsModalRef: BsModalRef;  
  public config = {
       animated: true,
       keyboard: false,
       backdrop: "static",       
       ignoreBackdropClick: false
  };
  constructor(private modalService: BsModalService) { 
  }

  public openLoadingIndicator() {          
    this.bsModalRef = this.modalService.show(**LoadingIndicatorComponent**,Object.assign({}, this.config, {class: 'modal-sm'}));               
  }

  public closeLoadingIndicator(){
    this.bsModalRef.hide();
  }  

}

@Component({
  selector: 'loading-indicator-content',
  templateUrl: './loading-indicator.html',
  styleUrls: ['./loading-indicator.css']
})
export class **LoadingIndicatorComponent** implements OnInit{     
  ngOnInit() { }          
  constructor( private bsModalRef: BsModalRef,private modalService: BsModalService,private loadingIndicatorService: LoadingIndicatorService) {  
  }     
}

Iam calling **LoadingIndicatorService** from **SerachLocations Component**.When usee put any location in search box pop up comes and popup should close once search is completed but it is not happening.

SerachLocations Component{

 some method(){
 LoadingIndicatorService.openLoadingIndicator();//popup is opening fine here
 //serach locations service will be called here
 LoadingIndicatorService.closeLoadingIndicator();//popup should hide when search is done but it is not closing
 }
}

0 个答案:

没有答案