模糊不工作 – Angular 2

前端之家收集整理的这篇文章主要介绍了模糊不工作 – Angular 2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正试图在角度2中设置一个蓝色事件,如下所示:

<div id="area-button" (blur)="unfocusAreaInput()" class="form-group" (click)="focusAreaInput()">

component.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()永远不会被执行.为什么?

解决方法

您的模糊事件无法正常工作,因为您的div无法在第一时间获得焦点.如果您将div添加tabindex =“1”(1可以替换为任何数字)或contentEditable(这将使div的内容可编辑)到您的div,它将能够获得焦点,然后模糊事件将起作用.此外,您可以使用焦点而不是单击.

猜你在找的Angularjs相关文章