Android上的Angular:“下一步”按钮没能聚焦CustomControlValueAccesor。
创始人
2024-10-10 03:00:27
0

在Android上,当使用Angular构建应用程序时,存在一个问题,即“下一步”按钮无法聚焦到Custom ControlValueAccesor。要解决这个问题,需要将控件手动聚焦。以下是解决该问题的示例代码:

(1)创建一个控件的示例,例如textarea

import { Component, forwardRef } from '@angular/core'; import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';

const CUSTOM_VALUE_ACCESSOR: any = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => MyInputComponent), multi: true, };

@Component({ selector: 'app-my-input', template: , providers: [CUSTOM_VALUE_ACCESSOR], }) export class MyInputComponent implements ControlValueAccessor { public onChange: (_: any) => void = noop; public onTouched: () => void = noop;

writeValue(value: any): void { const normalizedValue = value === null ? '' : value; this.myInput.nativeElement.value = normalizedValue; }

registerOnChange(fn: (_: any) => void): void { this.onChange = fn; }

registerOnTouched(fn: () => void): void { this.onTouched = fn; }

setDisabledState(isDisabled: boolean): void { this.myInput.nativeElement.disabled = isDisabled; } }

(2)使用以下代码强制聚焦:

import { Component, forwardRef } from '@angular/core'; import { MyInputComponent } from './my-input.component';

@Component({ selector: 'app-root', template: , }) export class AppComponent { public myValue: string; constructor(private readonly myInput: MyInputComponent) {}

public onClick(): void { this.myInput.writeValue(this.myValue); this.myInput.myInput.nativeElement.focus(); } }

通过在按钮上添加click事件,并在click事件处理程序中使用手动焦点强制聚焦,在Android上解决Angular中Custom ControlValueAccesor的下一步按钮聚焦问题。

相关内容

热门资讯

一分钟了解!wepoker破解... 一分钟了解!wepoker破解版内购(辅助挂)wpk透视插件(往昔真的是有挂);1、超多福利:超高返...
实测发现!鸿狐大厅脚本(辅助挂... 实测发现!鸿狐大厅脚本(辅助挂)fishpoker透视底牌(本然真的是有挂),鸿狐大厅脚本是用手机号...
一分钟揭秘!微乐小程序游戏破解... 一分钟揭秘!微乐小程序游戏破解器下载(辅助挂)德普之星透视(本然真的有挂);AI辅助机器人普及解说快...
必看攻略!丽水都莱大菠萝辅助(... 必看攻略!丽水都莱大菠萝辅助(辅助挂)wepoker透视脚本免费app(好像有挂);人气非常高,ai...
玩家必备教程!连连看辅助器手机... 玩家必备教程!连连看辅助器手机版(辅助挂)wepoker开脚本视频(竟然有挂);致您一封信;亲爱连连...
推荐一款!创思维正版辅助器下载... 推荐一款!创思维正版辅助器下载(辅助挂)聚星ai辅助工具收费多少(一直存在有挂);致您一封信;亲爱创...
最新研发!全民比鸡bug(辅助... 最新研发!全民比鸡bug(辅助挂)aapoker辅助怎么用(最初有挂);超受欢迎的全民比鸡bug稳赢...
盘点一款!八张透视辅助(辅助挂... 盘点一款!八张透视辅助(辅助挂)we-poker辅助器(确实真的是有挂);致您一封信;亲爱八张透视辅...
今日头条!微乐自建房怎么提高胜... 今日头条!微乐自建房怎么提高胜率(辅助挂)wepoker是不是有人用挂(竟然真的有挂);暗藏猫腻!微...
我来教教你!透视盒子(辅助挂)... 我来教教你!透视盒子(辅助挂)aapoker插件(本然是有挂);大家肯定在之前透视盒子或者透视盒子中...