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有辅助吗,微乐辅助脚本,模块教程(有挂教学)-哔哩哔哩1、wepoker有辅...
推荐透视!wepoker辅助器... 推荐透视!wepoker辅助器最新版本更新内容,广西微乐小程序控制器,机巧教程(有挂方式)-哔哩哔哩...
开挂透视!hhpoker是正规... 开挂透视!hhpoker是正规的吗,微信小程序微乐辅助免费版,窍门教程(有挂攻略)-哔哩哔哩一、hh...
揭露透视!wepokerplu... 揭露透视!wepokerplus作弊,微乐家乡官方免费下载安装,机巧教程(有挂教程)-哔哩哔哩1、玩...
科普透视!hhpoker透视脚... 科普透视!hhpoker透视脚本下载,微乐锄大地脚本,教材教程(详细教程)-哔哩哔哩hhpoker透...
总结透视!hhpoker脚本,... 总结透视!hhpoker脚本,微信小程序微乐房间透视,指引教程(有挂猫腻)-哔哩哔哩1、总结透视!h...
总结透视!wepoker好友局... 总结透视!wepoker好友局透视,微信微乐小程序有窍门吗,演示教程(有挂方式)-哔哩哔哩总结透视!...
揭幕透视!wepoker怎么看... 揭幕透视!wepoker怎么看牌型,微信小程序微乐辅助器免费版v2.0免费,总结教程(有挂功能)-哔...
辅助透视!拱趴大菠萝作弊方法,... 辅助透视!拱趴大菠萝作弊方法,微乐自建房脚本如何下载,窍要教程(有挂透视)-哔哩哔哩1、任何拱趴大菠...
解谜透视!wepoker透视破... 解谜透视!wepoker透视破解版,微乐小程序礼包码,方案教程(真实有挂)-哔哩哔哩1、超多福利:超...