我正在尝试在Angular 2中设置蓝色事件,如下所示:
<div id="area-button" (blur)="unfocusAreaInput()" class="form-group" (click)="focusAreaInput()">
组件.ts:
import { Component, ViewChild, ElementRef, Output, EventEmitter } from '@angular/core';
import { GoogleplaceDirective } from 'angular2-google-map-auto-complete/directives/googleplace.directive';
@Component({
selector: 'my-area',
directives: [GoogleplaceDirective],
templateUrl: 'app/find-page/area-picker.component.html',
styleUrls: ['app/find-page/area-picker.component.css']
})
export class AreaComponent {
public address: Object;
@ViewChild('areaInput') areaInput;
areaSelected: boolean = false;
@Output() onAreaSelected = new EventEmitter<boolean>();
@Output() onAreaDeselected = new EventEmitter<boolean>();
constructor(el: ElementRef) { }
getAddress(place: Object) {
this.address = place['formatted_address'];
var location = place['geometry']['location'];
var lat = location.lat();
var lng = location.lng();
console.log("Address Object", place);
}
focusAreaInput() {
this.areaInput.nativeElement.focus();
this.onAreaSelected.emit(true);
}
unfocusAreaInput() {
this.onAreaSelected.emit(false);
}
}
为什么unfocusAreaInput()从未被执行?