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的下一步按钮聚焦问题。

相关内容

热门资讯

大神推荐!互游辅助脚本,微乐山... 大神推荐!互游辅助脚本,微乐山西脚本插件,详细方法(确实有挂)1、上手简单,内置详细流程视频教学,新...
每日必看!道游互娱透视辅助截图... 每日必看!道游互娱透视辅助截图,开心泉州小程序辅助器,详细挂(有挂规律)开心泉州小程序辅助器破解侠是...
一分钟秒懂!乐酷大厅怎么安装,... 一分钟秒懂!乐酷大厅怎么安装,人海大厅软件辅助,详细脚本(有挂教学)一、人海大厅软件辅助游戏安装教程...
总算了解!518互游辅助,欢乐... 总算了解!518互游辅助,欢乐联盟免费辅助,详细方法(有挂细节)1、上手简单,内置详细流程视频教学,...
揭秘一下!吉祥填大坑脚本,天道... 揭秘一下!吉祥填大坑脚本,天道辅助器使用教程,详细工具(有挂分享)1、金币登录送、破产送、升级送、活...
分享一款!手机脚本辅助软件,腾... 分享一款!手机脚本辅助软件,腾威填大坑辅助,详细app(有挂讲解)小薇(辅助器软件下载)致您一封信;...
盘点一款!乐酷解码辅助,山西大... 盘点一款!乐酷解码辅助,山西大唐辅助器,详细工具(发现有挂)山西大唐辅助器能透视中分为三种模型:山西...
玩家爆料!微乐小程序辅助器免费... 玩家爆料!微乐小程序辅助器免费,陕西三代实战技巧,详细app(证实有挂)微乐小程序辅助器免费辅助器是...
终于懂了!微乐家乡破解版,威信... 终于懂了!微乐家乡破解版,威信茶馆跑辅助器,详细脚本(有挂规律)1、点击下载安装,威信茶馆跑辅助器脚...
推荐攻略!广西友乐免费辅助,联... 推荐攻略!广西友乐免费辅助,联盟辅助软件,详细工具(真的有挂)广西友乐免费辅助脚本下载中分为三种模型...