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、让任何用户在无需微乐自...
今日百科!微乐家乡麻将自建房辅... 今日百科!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)技巧今日百科!微乐家乡麻...
最新通报!微乐自建房辅助工具插... 最新通报!微乐自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)教程一、微乐自建房辅助工具插件...
玩家必看秘籍!微乐小程序麻将自... 玩家必看秘籍!微乐小程序麻将自建房辅助工具插件,微乐小程序免费黑科技(开挂自建房)软件1、超多福利:...
记者发布!微乐家乡麻将自建房辅... 记者发布!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)攻略1)微乐家乡麻将自建...
科技通报!微乐微信自建房辅助工... 科技通报!微乐微信自建房辅助工具插件,微乐家乡麻将自建房辅助app(开挂自建房)攻略微乐微信自建房辅...
分享实测!微乐自建房辅助工具脚... 分享实测!微乐自建房辅助工具脚本,微乐自建房脚本免费入口(开挂自建房)工具进入游戏-大厅左侧-新手福...
今日公布!微乐自建房辅助工具脚... 今日公布!微乐自建房辅助工具脚本,微乐家乡麻将自建房辅助app(开挂自建房)教程1)微乐家乡麻将自建...
总算了解!微乐小程序自建房辅助... 总算了解!微乐小程序自建房辅助工具插件,微乐小程序免费黑科技(开挂自建房)插件1、微乐小程序自建房辅...
玩家必看秘籍!微乐小程序自建房... 玩家必看秘籍!微乐小程序自建房辅助工具插件,微乐家乡麻将自建房辅助app(开挂自建房)工具;1、首先...