html - 如何禁用 Angular 匹配

标签 html angular typescript disabled-input ngx-chips

所以我有 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"这样用户就不能添加或删除它。我不想对此进行硬编码,而是想使用图表详细信息组件复选框来控制它。

enter image description here

它不会运行,但我已将这两个组件的完整代码附在此处 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

关于html - 如何禁用 Angular 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62666130/

相关文章:

Angular2 在组件之间共享数据

angular - Assets 未考虑基本 href url - 未找到错误

javascript - 如何使用异步将错误传递回调用者函数?

typescript - typescript 中函数返回类型的扩展是什么

python - 使用lxml删除中文HTML文件中的多余空格

html - Chrome 中带有圆 Angular 边框的 `overflow:hidden` 父级泄漏

更新数组时 Angular 2 不更新

javascript - 计算在 HTML5 canvas 径向进度条中点击的百分比

html - border-radius 50% 和 100% 有什么区别?

javascript - typescript :有没有办法检查变量是否是具有嵌套属性的接口(interface)定义对象?