html - 如何禁用 Angular 匹配

所以我有 Tags 组件,并将该组件导入到我的 Chart-details 组件中。在我的图表详细信息组件中,我有一个复选框,它将禁用所有输入框、下拉框、位于图表详细信息页面内的按钮,但由于某些原因,当我单击该复选框时,我导入的标签组件没有被禁用。非常感谢有关如何解决此问题以便用户在单击复选框时无法添加或删除标签的任何建议或帮助。

图表详细信息组件。 HTML

//Check box to disable all the input, drop down, buttons
    <mat-checkbox *ngIf="chart && workspace" color="primary" [disabled]="this.workspace.type === WorkspaceType.user"
        [(ngModel)]="chart.isPublished" (ngModelChange)="publishChange($event)">Published</mat-checkbox>

//Example Button
   <button color="primary" mat-flat-button (click)="saveClick()" [disabled]="this.chart.isPublished">Save</button>

// Imported Tags Component
        <mc-tags [_normalTags]="chart.tags" [removable]="true" [selectable]="true"
        (added)="tagAdded($event)" (removed)="tagRemoved($event)" [disabled]="this.chart.isPublished" >
        </mc-tags>

我添加了 [disabled]="this.chart.isPublished"但我收到一条错误消息“无法绑定(bind)到‘disabled’,因为它不是‘mc-tags’的已知属性。”。我也尝试过(禁用)但仍然无法正常工作,即使选中了复选框,用户仍然可以添加或删除标签。

标签组件.HTML

        <mat-chip-list #chipList [disabled]="true">
            <mat-chip *ngFor="let chip of normalTags" [selectable]="selectable" 
            [removable]="removable"
                (removed)="removeTags(chip)">
                {{chip.tag}}
            </mat-chip>

            <input matInput #input [(ngModel)]="tagIn" [formControl]="tagCtrl2" 
            [matAutocomplete]="auto" />
        </mat-chip-list>

现在我必须在 Tags component.html 中的 mat-chip-list 上做 [disabled]="true"这样用户就不能添加或删除它。我不想对此进行硬编码,而是想使用图表详细信息组件复选框来控制它。

它不会运行,但我已将这两个组件的完整代码附在此处 https://stackblitz.com/edit/angular-ivy-wwfcai .谢谢

最佳答案

您可以使用 Input 传递 true 或 false,然后您可以禁用标签。

//复选框禁用所有输入、下拉、按钮

    <mat-checkbox *ngIf="chart && workspace" color="primary" [disabled]="this.workspace.type === WorkspaceType.user"
        [(ngModel)]="chart.isPublished" (ngModelChange)="publishChange($event)">Published</mat-checkbox>

//Example Button
   <button color="primary" mat-flat-button (click)="saveClick()" [disabled]="this.chart.isPublished">Save</button>

// Imported Tags Component

您可以使用 pointer-events:none; 来禁用它。您还可以应用条件 CSS

<div style="pointer-events:none;">
        <mc-tags [_normalTags]="chart.tags" [removable]="true" [selectable]="true"
        (added)="tagAdded($event)" (removed)="tagRemoved($event)" [disabled]="this.chart.isPublished" >
    </ div>
        </mc-tags>
enter code here

https://stackoverflow.com/questions/62666130/

相关文章:

ios - 即使不再显示,SwiftUI View 也会不断更新

python - 线程 Tornado + flask 应用程序的正确方法是什么?

reactjs - 在 cookie 接受横幅后重新初始化 i18next 实例

perl - agl 构建在 "recipe perl-native-5.24.4-r0: task

javascript - 如何使用 Cypress 将变量的存储值获取到 URL 命令中?

google-apps-script - 如何使用 GAS 获取文档中的 URL 并将其替换为 UR

python - 使用 python 抓取谷歌精选片段

python - 如何使用 OpenCV 网络摄像头视频和其他 wx 组件(在同一框架/面板内)创建

python - 新建 Postgresql 数据库 : column "id" is of typ

angular - 具有父/子关系的 Angular 组件中的通用类型定义