intellij-platform-psi 相关问题


绑定了formControlName后,如何在html中使用它?

我当前有问题的 html 部分是这样的 ... 我的 html 当前有问题的部分是这个 <div class="psi-list"> <div class="flex-row" *ngFor="let item of psiList; index as i"> <p class="row-psi">{{ item.psi }}</p> <button class="icon-btn" (click)="deletePsi(item.psi)"><i class="cil-trash"></i></button> <button class="icon-btn" (click)="item.toggle = !item.toggle"><i class="cil-pen-alt"></i></button> <form [formGroup]="psiEditForm" id="psi-edit-form" class="form-horizontal" [hidden]="!item.toggle"> <input class="psi-input" type="text" placeholder="Update PSI here..." [(ngModel)]="psiEdit" [ngClass]="{'is-valid': !checkControlValidation(psiEditForm.controls.psi) && psiEditForm.controls.psi.touched, 'is-invalid': checkControlValidation(psiEditForm.controls.psi)}" (keydown.enter)="!psiEditForm.controls.psi.invalid ? editPsi(item.psi) : clearPsiEdit()" formControlName="psi" /> <div class="help-block validation-warning" *ngIf="checkControlValidation(psiEditForm.controls.psi)"><i class="fa fa-exclamation fa-lg"></i>Please Enter a Valid 2 Letter PSI</div> </form> </div> </div> 我使用 formControlName“psi”将控件传递给 .ts 文件中的 checkControlValidation 方法。然而,这会导致功能问题。每当我在一个输入框中输入内容时,它都会将其输入到 *ngFor 中的所有输入框中。 当我将表单控件名称更改为这个时 - [formControlName]="item.psi" 它将名称绑定到与其相关的项目,因此理论上我可以通过它来解决我的问题。但是,当我将 psiEditForm.controls.psi 的所有实例更改为 psiEditForm.controls.item.psi 时,我收到很多 TS2339 错误。 我有什么想法可以使用它吗?抱歉,我知道这可能措辞很糟糕 尝试这样 <div class="psi-list"> <div class="flex-row" *ngFor="let item of psiList; index as i"> <p class="row-psi">{{ item.psi }}</p> <button class="icon-btn" (click)="deletePsi(item.psi)"><i class="cil-trash"></i></button> <button class="icon-btn" (click)="item.toggle = !item.toggle"><i class="cil-pen-alt"></i></button> <form [formGroup]="psiEditForm" id="psi-edit-form" class="form-horizontal" [hidden]="!item.toggle"> <input class="psi-input" type="text" placeholder="Update PSI here..." [(ngModel)]="psiEdit" [ngModelOptions]="{standalone: true}" [ngClass]="{'is-valid': !checkControlValidation(psiEditForm.controls.psi) && psiEditForm.controls.psi.touched, 'is-invalid': checkControlValidation(psiEditForm.controls.psi)}" (keydown.enter)="!psiEditForm.controls.psi.invalid ? editPsi(item.psi) : clearPsiEdit()" formControlName="psi" /> <div class="help-block validation-warning" *ngIf="checkControlValidation(psiEditForm.controls.psi)"> <i class="fa fa-exclamation fa-lg"></i>Please Enter a Valid 2 Letter PSI </div> </form> </div> </div>


Pop_os:如何为 intellij 创建命令行启动器

在 Pop_os 上: 当在项目文件夹中时,我想输入“intellij”。并在 intellij 中打开该项目。 官方说明说进入主菜单并使用 “工具/创建命令-l...


为什么斐波那契数列在实践中不使用封闭形式?

斐波那契数列有一个封闭形式,可以通过生成函数获得。这是: f_n = 1/sqrt(5) (phi^n-\psi^n) 有关这些术语的含义,请参阅上面或此处的链接。 然而,...


安装 Google Cloud Platform for Eclipse 时出错:缺少 javax.annotation 依赖项

我在尝试安装适用于 Eclipse 的 Google Cloud Platform 插件时遇到问题。安装过程失败并显示以下错误消息: 无法完成安装,因为...


IntelliJ IDEA - 如何重新连接控制台选项卡并将其放回 IDE

我是 IntelliJ IDEA 新手(正在使用 2017.1.3)... 不小心,我的控制台选项卡窗口浮动了,并且似乎无法将其重新连接到 IntelliJ IDEA。当我运行调试器时,它作为单独的 win 启动...


Kotlin - IntelliJ 项目设置

我想使用 IntelliJ IDE 为 JVM 启动一个新的 Kotlin 项目,但我无法获得让它工作的配置。我试图按照本教程进行操作,但之后不起作用(...


构建进程异常终止 IntelliJ IDEA

很长一段时间以来,我在尝试在 Intellij IDEA Community Edition 2023.3 中编译任何 Java 程序时遇到各种错误。 编译以下代码时: 导入 javax.swing.*; 导入jav...


在 Jenkins 管道中使用“docker buildx build”时出现“未知标志:--platform”

我使用的是RedHat-7系统。我希望通过 Jenkins Pipeline 来实施 DevOps。 但是当我使用 docker buildx 构建功能时,Jenkins 说“未知标志:--platform”。 我运行我的詹金斯......


如何在intellij中设置和运行scala-spark?

我正在尝试运行使用 Intellij 来构建用 scala 编写的 Spark 应用程序。当我执行scala程序时,出现以下错误: 线程“main”java.lang 中出现异常。


Java Web App - 尝试运行 JSP 文件 (IntelliJ) 时出现错误 404

当我尝试运行 JSP 文件(右键单击文件名并在 IntelliJ 中运行)时,我得到 404 我的JSP代码: `<%@ page contentType="text/html; charset=ISO-8859-1" pageEncoding=...


如何删除所有 Google Cloud Platform (GCP) 资源中的资源级权限

如何删除所有 Google Cloud Platform (GCP) 资源中的资源级权限? 例如,计算虚拟机实例可共享给另一个 GCP 用户,而无需分配 IAM 角色。有没有...


如何使用IntelliJ IDEA配置maven服务器?

我是maven和tomcat的新手,我尝试使用IntelliJ IDEA运行tomcat。 我使用以下命令安装了maven:brew install maven。 我还有一个文件夹 /opt/homebrew/Cellar/maven/3.9.6/libexec 为什么不接受...


IntelliJ Idea Spring boot 应用程序在 Temp 中创建 tomcat 文件夹

我在 IntelliJ Idea 中遇到 Spring Boot 项目问题 - 每次我通过 IDE 启动项目时,Tomcat 都会在 appdata\local emp 中创建名为“tomcat.8080.X\work\Tomcat\localhost...”的新工作目录。


Intellij Koltin/java 属性名称“désactivé”只能包含字母和数字

我尝试使用重音字符作为变量名称,但 intellij 并不喜欢它 经过一些测试后,这在编译甚至使用时都不会造成问题 我从管理


使用终端和集成终端(IntelliJ IDE CE)安装jenkins有什么区别?

我一直在努力了解这个 Jenkins 开源。我以前从未使用过詹金斯。使用 IntelliJ IDE 安装它后,我意识到在安装它之前,您需要 ins...


当任何更改发生时,IntelliJ 自动重建不起作用

我在 intelliJ 中使用 kotlin 处理 Spring Boot 项目。 作为一项设置,我尝试在代码发生任何更改时重新构建并按 ctrl+s。 我自动检查构建项目 我检查允许...


将 JDK 17 升级到 21 后,在 intelliJ 中获取 java 代理已加载警告

我刚刚在我的 Windows 计算机中从 JDK 17 升级到 21。之后,当我在 IntelliJ 中运行 JUNIT 测试时,我遇到了以下问题。我查了一整天了,还是没有……


IntelliJ IDEA 数据抓握 - NotSerializedException:MongoDB 查询中的 com.oracle.truffle.api.TruffleStackTraceElement

我正在使用查询控制台进行 MongoDB 查询。 让 ids = db.collection.aggregate([ { $匹配:{ ... } }, { $组:{ _id:“$字段” } ...


尝试使 java 项目可执行时,Artifact 文件夹未出现在 Intellij 的“out”目录中

我试图在Intellij中使我的java项目可执行,我一步一步正确地完成了所有事情,但是添加工件后没有工件文件夹,任何人都可以帮忙吗?一切似乎都是


为什么我不能使用数据类的字段作为jetpack compose中lazyColumn的item的key?

一个非常非常简单的例子(implementation(platform("androidx.compose:compose-bom:2023.08.00"))): com.study.myapplication 包 导入 android.os.Bundle 导入 androidx.activity。


使用 VS Code 提供额外的配置文件

我们如何使用 Visual Studio Code 使用 https://github.com/ballerina-platform/ballerina-spec/blob/master/configurable/spec.md# located-toml-files 中指定的多个 .toml 文件? (假设...


更新API Platform 3.0相关实体

我正在尝试通过主实体更新相关实体。例如,我有产品和优惠。我向 /products 发了一个帖子 { "name": "样品产品", “优惠”:...


如何使用 Docker 在 Ubuntu 上安装 nvm?

到目前为止我有这个: 来自 --platform=linux/amd64 amd64/ubuntu:noble 环境术语 Linux ENV DEBIAN_FRONTEND 非交互式 SHELL [“/bin/bash”,“-c”] 环境外壳 /bin/bash 运行 apt upd...


在 Hyperledger Firefly Fabric 中部署链码时出错

当您运行以下命令来发起智能合约时: ff 部署结构开发测试 asset_transfer.zip firefly asset_transfer 1.0 我收到以下错误: 错误:docker run --platform linux/...


如果类型是从变量进行数据绑定,则通过 <object> 标签在 Angular 中显示 pdf 无法在 Chrome 中工作

我正在尝试通过 标签在 Chrome 中显示 pdf。 如果我手动编写类型,它会起作用: 不工作 但是... 我正在尝试通过 <object> 标签在 Chrome 中显示 pdf。 如果我手动写 type: 就可以了 <object [data]="getUrl(true)" type="application/pdf"> Not working </object> 但如果我从变量读取类型则不会: <object [data]="getUrl(true)" [type]="file.mimeType"> Not working </object> 为什么?这是一些非常奇怪的错误,还是我做错了什么可怕的事情。 这里是plunkr。 它可以在 Firefox 中运行(所有 4 个对象都会显示),但不能在 Chrome 中运行 (Version 74.0.3729.169 (Official Build) (64-bit)): 我遇到了同样的问题,但我不明白原因。 就我而言,我决定在基于 Blink 引擎的浏览器中使用“embed”元素而不是“object”元素。 <ng-template #blinkPlatformViewer> <embed [src]="getUrl(true)" [type]="file.mimeType"/> </ng-template> <object *ngIf="!isBlinkPlatform; else blinkPlatformViewer" [data]="getUrl(true)" [type]="file.mimeType"> Not working </object> import { Platform } from '@angular/cdk/platform'; import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'; export class FileContentComponent { constructor(private readonly sanitizer: DomSanitizer, private readonly platform: Platform) { } get isBlinkPlatform(): boolean { return this.platform.BLINK; } }


如何使用 API Platform 和 Gedmo Translatable 查询可翻译属性

我正在使用 Symfony 6 + API 平台 + Gedmo Translatable。 更新/发布项目工作正常并正确存储翻译。 另外,以正确的语言获得集合是......


为什么 PDFBox 添加到 IntelliJ Java 中的库和模块后会出现意外错误?

我收到以下错误: /Users/用户名/IdeaProjects/WrestlingProject/src/DataScraper.java:22:41 java:无法访问org.apache.pdfbox.io.RandomAccessRead 组织的类文件。


无法验证应用程序默认凭据

我正在关注这里的文档,它说: 应用程序向 Google Cloud Platform API 服务进行身份验证的最简单方法是使用应用程序默认凭据 (ADC)。服务使用...


从spark/scala项目代码中资源文件夹中的sql文件读取查询

我在 IntelliJ 中的文件夹结构如下 src-->主-->资源-->sql-->samplequery.sql 我在文件夹 src--> main-->scala-... 中有 scala 对象文件samplequeryexecute


如何在云端托管Python项目(特别是Google Cloud Platform)

我有一个关于在云服务器上托管个人项目的非常简单的(我认为)问题。目前,我每天早上都手动运行我的脚本。我想通过


Jakarta EE:JSF 标签未转换为 HTML 标签

我已经在 IntelliJ Idea Ultimate (Maven) 中为 Java Enterprises 的大学项目设置了 Jakarta EE 项目,并且还可以在浏览器中输出 index.xhtml(通过 Tomcat 8.5.87)。我是另一个...


无法加载DLL“找不到模块HRESULT:0x8007007E”

我有 C# WPF 应用程序,其中使用了 C++ DLL 库。当我构建项目时,它会成功构建,并且所有 DLL 和 exe 都存储在 bin/(Platform) eg(bin/Debug) 文件夹中。 现在如果我...


应用程序无法识别手势,例如在 Angular 11 中使用 Hammer.JS 进行平移

我无法在使用 Hammer.JS 的 Angular 应用程序中识别任何手势,例如滑动、平移。它的设置是这样的: 包.json: “@角度/核心”:“11.0.5”, “@Angular/platform-br...


使用intellij Idea练习Java

我是一个完全的新手,我正在练习数组。当编写 String myArray[] 时,我在方括号中收到错误。我实际上是在复制我用来学习的视频屏幕,并且我......


Intellij 自定义 VM 选项

我的大多数运行配置中有一个自定义虚拟机选项:“${eclipselink-javaagent}”,我需要编辑它,但我找不到任何方法来做到这一点。我是不是错过了什么?


在 Spring-MVC 中显示 JSP 页面时出现问题

我在 Spring-MVC 中显示 jsp 页面时遇到问题。 这是带有 Gradle 和 IntelliJ CE 的基本 hello world Spring-MVC: 我收到以下错误页面: 这是我的 build.gradle: 构建脚本{


404 错误 - 尝试访问我的 Servlet 时显示错误

主页工作正常,但是,当我尝试访问我正在测试的两个 servlet 之一时,出现 404 错误。我使用IDE intellij,tomcat 9,maven,servlet版本5, HTTP 状态 404...


在 Docker 中的 Ubuntu 上安装最新版本 Node (v20) 的说明不起作用?

我只是按照说明在 Ubuntu 上的 docker 中安装了最新版本的 Node (v20),在我的 Dockerfile 中包含以下内容: 来自 --platform=linux/amd64 ubuntu:22.04 运行 apt-get update 运行 apt-get...


launchctl 配置用户路径有什么作用?

我在 MacOS 中的 PATH 环境变量遇到了一个奇怪的问题,我花了几个小时来调试: 前段时间,当我试图解决 IntelliJ 终端 PATH 变量不存在的问题时...


intellij IDEA 中的 Java 实时模板在块注释中行为不正确?

我正在定义自己的实时模板,在块注释内使用(依赖)变量时(未测试行注释),该行为似乎是错误的。 我的模板: $评论开始$* *


致命错误C1034:stdio.h:未指定包含文件的搜索路径。 GraalVM Native Image 没有编译我的项目

GraalVM 没有编译我的项目,我尝试了以下方法: PS D:\Documents\Intellij Idea Projects\Project> ./gradlew.bat nativeRun 配置项目: 项目:=>“com.user.Project”Java 模块 任务:


如何在 AWS Elastic Beanstalk 环境/应用程序中运行 artisan migrate?

我已经完成了所有这些事情来部署我的应用程序,但我无法在部署中运行 php artisan migrate。我已经尝试了从container_commands到.ebextensions/.platform/hooks的许多解决方案,但没有任何效果......


无法识别的虚拟机选项“AggressiveOpts”

我正在尝试使用 Java 8 在 intelliJ 中运行我的加特林项目。 我知道 VM 选项“AggressiveOpts”在 Java 11 中已被弃用,并在 Java 12 中被删除,但我想知道为什么我会得到这个......


为 IntelliJ IDEA 添加 JSON 语法突出显示以用于 .liquid 文件

我已经能够按照此处的说明向我的 .liquid 文件添加语法突出显示:在 webStorm/phpStorm 中启用 Liquid 模板语法突出显示 它对我的 HTML 运行良好并且...


IntelliJ 中的“手表”是什么以及如何使用它们?

当我调试应用程序时,调试工具窗口中有一个“Watches”窗口。我把这本手册读了一遍又一遍,但找不到任何手表的实际用途。 不知何故,我认为这很酷,而且你...


log4j2 使用 Maven 将所有日志写入 Spring Boot 3.1.0 中的特定文件时出现问题

我正在尝试设置 log4j2 将所有日志写入特定文件。我尝试了在互联网上找到的各种方法,但日志仍然只显示在控制台中。 我正在使用 IntelliJ IDEA CE。 春天...


具有 TimestampableEntity 特征的实体在 PUT 操作中失败

我正在全新安装 API Platform (v3.2.7),并且使用 Gedmo\Timestampable\Traits\TimestampableEntity 这是我的实体(问候语示例) 我正在全新安装 API Platform (v3.2.7),并且正在使用 Gedmo\Timestampable\Traits\TimestampableEntity 这是我的实体(问候语示例) <?php namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Gedmo\Timestampable\Traits\TimestampableEntity; #[ApiResource] #[ORM\Entity] class Greeting { use TimestampableEntity; #[ORM\Id] #[ORM\Column(type: "integer")] #[ORM\GeneratedValue] private ?int $id = null; #[ORM\Column] #[Assert\NotBlank] public string $name = ""; public function getId(): ?int { return $this->id; } } 和我的 config/services.yaml gedmo.listener.timestampable: class: Gedmo\Timestampable\TimestampableListener tags: - { name: doctrine.event_listener, event: 'prePersist' } - { name: doctrine.event_listener, event: 'onFlush' } - { name: doctrine.event_listener, event: 'loadClassMetadata' } 它在 POST 操作上工作正常,但在执行 PUT 时失败。我收到此错误 执行查询时发生异常:SQLSTATE[23000]: 完整性约束违规:1048 列“created_at”不能 空 我使用的版本是:symfony 6.4.1,doctrine 2.12,gedmo 3.14 我最终做的是使用 PATCH 而不是 PUT。所以我可以编辑部分实体,并且特征仍然更新 updated_at 字段


NG8001:“app-welcome”不是已知元素:

我的 Angular 应用程序遇到问题,收到错误 8001。我不知道如何处理它。谁能帮我这个?谢谢你! 应用程序组件.html {{标题}}&l... 我的 Angular 应用程序遇到问题,收到错误 8001。我不知道如何处理它。谁能帮我这个?谢谢! app.component.html <h1>{{ title }}</h1> <p>Congratulations! Your app is running. 🎉</p> <app-welcome></app-welcome> app.component.ts import { Component } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterOutlet } from '@angular/router'; @Component({ selector: 'app-root', standalone: true, imports: [CommonModule, RouterOutlet], templateUrl: './app.component.html', styleUrl: './app.component.css' }) export class AppComponent { title = 'XYZCARS'; } welcome.component.ts import { Component } from '@angular/core'; @Component({ selector: 'app-welcome', templateUrl: './welcome.component.html', styleUrl: './welcome.component.css' }) export class WelcomeComponent { car = 'toyota'; } 我的项目最初没有 app.module.ts 文件。我自己添加了它并根据网上找到的一些信息进行了配置,但问题仍然存在并且仍未解决。谁能帮我解决这个问题吗? app.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { WelcomeComponent } from './welcome/welcome.component'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent, WelcomeComponent ], imports: [ BrowserModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } 如果您正在 Angular 17 中创建项目->使用这些命令 ng app --no-standalone 然后你就得到了 app.module.ts 文件。


.NET MAUI、ios UseSafeArea 不工作 StackLayout、VerticalStackLayout 和 Grid

<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Test.Views.Activities.ActivityMapList" xmlns:maps="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps" xmlns:sensors="clr-namespace:Microsoft.Maui.Devices.Sensors;assembly=Microsoft.Maui.Essentials" xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls" ios:Page.UseSafeArea="False" Shell.NavBarIsVisible="False" Style="{StaticResource Key=DefaultPage}"> <ContentPage.Content> <StackLayout> <maps:Map VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> <x:Arguments> <MapSpan> <x:Arguments> <sensors:Location> <x:Arguments> <x:Double>36.9628066</x:Double> <x:Double>-122.0194722</x:Double> </x:Arguments> </sensors:Location> <x:Double>0.01</x:Double> <x:Double>0.01</x:Double> </x:Arguments> </MapSpan> </x:Arguments> </maps:Map> </StackLayout> </ContentPage.Content> </ContentPage> StackLayout 或 Grid 内的地图控件,iOS 的 SafeArea 为 false,如图所示。 你有什么解决办法吗? 我需要在地图上使用网格或堆栈布局 默认情况下.NET MAUI 将考虑安全区域。所以使用特定于平台的UseSafeArea就是禁用安全区域。目前,将 UseSafeArea 设置为 false 不会改变行为(尽管应该如此),这是一个错误。另请参阅 MAUI github 上的问题:https://github.com/dotnet/maui/issues/5856 您还可以设置 IgnoreSafeArea 属性来实现相同的目的。但是,它不再在 .NET 7 中工作,请参阅以下问题:https://github.com/dotnet/maui/issues/12823 要解决您的问题,您需要将 IgnoreSafeArea="True" 添加到您的 Grid 或 StackLayout 并将 ios:Page.UseSafeArea="False" 添加到您的页面。这应该不是必需的,但这是对我有用的解决方法。 有关在 iOS 上禁用安全区域的文档可以在此处找到:https://learn.microsoft.com/en-us/dotnet/maui/ios/platform-specifics/page-safe-area-layout?view=net-毛伊岛-7.0 您可以设置 Page Padding 值来实现。在OnAppearing方法中,设置页面的safeInsets,如下代码: protected override void OnAppearing() { base.OnAppearing(); DeviceSafeInsetsService d = new DeviceSafeInsetsService(); double topArea = d.GetSafeAreaTop(); double bottomArea = d.GetSafeAreaBottom(); var safeInsets = On<iOS>().SafeAreaInsets(); safeInsets.Top = -topArea; safeInsets.Bottom = -bottomArea; Padding = safeInsets; } 要获取 topArea 和 bottomArea 值,您应该编写平台代码。答案末尾附有有关此内容的更详细教程。 首先你可以在Project文件夹中生成一个新的类文件并将其更改为部分类。生成两个部分方法。 public partial class DeviceSafeInsetsService { public partial double GetSafeAreaTop(); public partial double GetSafeAreaBottom(); } 然后在iOS平台生成部分文件并实现。该文件位于 Project/Platform/iOS 文件夹中,我想提一下的是,该文件是一个部分文件,因此命名空间应与上面的文件相同。生成此文件时,请删除命名空间中的 .Platforms.iOS 后缀。 public partial class DeviceSafeInsetsService { public partial double GetSafeAreaBottom() { if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow(); var bottomPadding = window.SafeAreaInsets.Bottom; return bottomPadding; } return 0; } public partial double GetSafeAreaTop() { if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow(); var TopPadding = window.SafeAreaInsets.Top; return TopPadding; } return 0; } } 更多信息,您可以参考如何在.NET MAUI中编写特定于平台的代码和MauiPlatformCode示例代码 希望它对你有用。


选中/取消选中 mat-checkbox 未正确返回 true 或 false

我正在使用 Angular 15 和 Angular Material 14,下面是我用来显示复选框列表的 HTML 代码 我正在 Angular 15 和 Angular Material 14 工作,下面是我用来显示复选框列表的 HTML 代码 <div *ngFor="let control of checkboxArray.controls;let i = index" > <mat-checkbox [formControl]="control" (input)="validateInputs(notificationForm)" [checked]="control.value" (change)="control.checked=$event.checked;onCheckedChange(i);"> {{ checkboxItems[i].name }} </mat-checkbox> </div> 下面是Angular中onCheckedChange函数的代码 onCheckedChange(index: number) { this.sortCheckboxArray(); const checkboxItem = this.checkboxItems[index]; const control = this.checkboxArray.at(index); if (control) { if (control.value) { this.lists.push(checkboxItem.id.toString()); } else { this.lists.pop(checkboxItem.id.toString()); } } this.updateSubscriberGroupsCount(); this.cdr.detectChanges(); } 当我选中复选框时,在这个 onCheckedChange 函数中,control.value 始终返回 false。哪里出了问题?无法理解.. 这是一个工作版本,复选框逻辑工作正常,希望有帮助! 我们需要使用control.value获取表单组,但我们还需要访问内部表单控件,然后获取复选框值! import { CommonModule } from '@angular/common'; import { Component } from '@angular/core'; import { FormArray, FormControl, FormGroup, ReactiveFormsModule, } from '@angular/forms'; import { bootstrapApplication } from '@angular/platform-browser'; import 'zone.js'; import { MatCheckboxModule } from '@angular/material/checkbox'; @Component({ selector: 'app-root', standalone: true, imports: [CommonModule, ReactiveFormsModule, MatCheckboxModule], template: ` <form [formGroup]="form"> <div formArrayName="array"> <div *ngFor="let control of checkboxArray.controls;let i = index" [formGroupName]="i"> <mat-checkbox formControlName="test" style="margin-bottom: 15px;" (change)="onCheckedChange(i);"> {{ checkboxItems[i].name }} </mat-checkbox> </div> </div> </form> `, }) export class App { name = 'Angular'; form = new FormGroup({ array: new FormArray([]), }); lists = []; checkboxItems: any = []; ngOnInit() { this.add(); this.add(); this.add(); } add() { this.checkboxArray.push( new FormGroup({ test: new FormControl(false), }) ); this.checkboxItems.push({ name: 'test' }); } get checkboxArray() { return this.form.get('array') as FormArray; } onCheckedChange(index: number) { // this.sortCheckboxArray(); // const checkboxItem = this.checkboxItems[index]; const control = this.checkboxArray.at(index); if (control) { if (control.value.test) { console.log('checked'); // this.lists.push(checkboxItem.id.toString()); } else { console.log('not checked'); // this.lists.pop(checkboxItem.id.toString()); } } // this.updateSubscriberGroupsCount(); // this.cdr.detectChanges(); } } bootstrapApplication(App); 堆栈闪电战


© www.soinside.com 2019 - 2024. All rights reserved.