如何在ng4-geoautocompelete

时间:2018-05-28 11:46:17

标签: angular typescript google-geolocation google-location-services

我在自定义组件中使用了ng4-autocomplete组件,我希望在自动完成下拉列表关闭时检测到更改。你能否告诉我你如何实施“closeAutocomplete”方法?

这是我的location.component.html

<ng4geo-autocomplete (click)="showAutocomplete()"
                     [userSettings]="location"
                     (componentCallback)="componentCallback123($event)" placeholder=""
                     (closeAutocomplete)="closeAutocomplete($event)"
>
</ng4geo-autocomplete>

以下是location.component.ts文件。

import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';

@Component({
    selector: 'mitra-location',
    templateUrl: './location.component.html',
    styleUrls: ['./location.component.scss']
})
export class LocationComponent implements OnInit {
    @Input('location') location = '';

    @Output('callback') callback = new EventEmitter<any>();

    locationElem;

    ngOnInit() {
        this.locationElem = document.getElementById('geo-location');
    }

    closeAutocomplete(event) {
        // Here i want to get this event
    }
}

This是此组件的文档链接。

谢谢!

1 个答案:

答案 0 :(得分:0)

正如您在documentation中看到的那样,import { NativeStorage } from "@ionic-native/native-storage"; const STORAGE_KEY = 'hospitals'; ... rootPage:any; constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public push: Push, public alertCtrl: AlertController, private nativeStorage: NativeStorage) { platform.ready().then(() => { // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. statusBar.styleDefault(); splashScreen.hide(); this.pushsetup(); this.setRootPage(); }); } private setRootPage(){ let localStorage:string = "Not got"; this.nativeStorage.getItem(STORAGE_KEY) .then( item => localStorage = item.properity, error => console.log("Error getting item. Error: " + error) ); alert(localStorage); switch (localStorage){ case "123": this.rootPage = LoginPage; break; default: this.rootPage = IntroPage; break; } } 组件上未定义func getDistrictList() -> Void { let reachable = Reachability()! let tempDict = NSMutableDictionary() let user = UserDefaults.standard.object(forKey: "user_data") as! NSDictionary tempDict.setValue(user.object(forKey:"user_id")!, forKey: "user_id") tempDict.setValue(AppDelegate.appDelegateObject().languageToSend(), forKey: "lang_code") if reachable.isReachable { Services.requestForUpdatedWallet(postDic: tempDict, completion: { (result) in let isSuccess = result["success"] as! Bool if isSuccess { DispatchQueue.main.sync { if result["wallet_amount"] != nil { self.labelWallet.text = "\(AppDelegate.appDelegateObject().localLanguage(key: "available_money", comment: "")) \(result["wallet_amount"] as! String) €" self.stringWallet = result["wallet_amount"] as! String }else{ self.labelWallet.text = "\(AppDelegate.appDelegateObject().localLanguage(key: "available_money", comment: "")) 0 €" self.stringWallet = "0" } MBProgressHUD.hideAllHUDs(for: self.view, animated: true) // self.tblDistrict.reloadData() } } }) } // else{ // self.showAlert(title: AppDelegate.appDelegateObject().localLanguage(key: "app_name", comment: ""), message: AppDelegate.appDelegateObject().localLanguage(key: "no_internet", comment: "")) // } } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ } 输出

唯一定义的输出是closeAutocomplete(),您已正确调用它。您不能在组件上调用ng4geo-autocomplete,因为它不是组件的输出属性。