gpt4 book ai didi

angular - 模糊不起作用 - Angular 2

转载 作者:太空狗 更新时间:2023-10-29 17:22:04 25 4
gpt4 key购买 nike

我正在尝试像这样在 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() 永远不会被执行。为什么?

最佳答案

您的 blur 事件不起作用,因为您的 div 首先无法获得焦点。如果您将 tabindex="1"(1 可以替换为任何数字)或 contentEditable(这将使 div 的内容可编辑)添加到您的 div,它将能够获得焦点,然后 blur 事件将起作用。此外,您还可以使用 focus 而不是 click

关于angular - 模糊不起作用 - Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39259775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com