我如何使整个行可单击以及单击复选框时如何更改行颜色?
这是我的html文件
<section class="others">
<div class="sub-header">Others</div>
<p class="text-center" *ngIf="otherTests.length === 0">No Tests Available</p>
<app-custom-accordion [closeOthers]="true">
<ngb-panel [disabled]="true" *ngFor="let testPanel of otherTests" id=". {{testPanel.Id}}" [title]="testPanel.Name">
<ng-template ngbPanelTitle>
<div class="action-items">
<span class="material-icons fav" [class.favorited]="testPanel.Favorite" (click)="onFavoriteClick(testPanel)"></span>
<span class="icon-set" [ngClass]="{'same-day-2x': isSameDay(testPanel.Code), 'next-day-2x': isNextDay(testPanel.Code)}"></span>
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" [name]="testPanel.Id + '-' + testPanel.Moniker" [ngModel]="panelIds.indexOf(testPanel.Id) > -1"
(ngModelChange)="onPanelCheckboxUpdate($event, testPanel)" [id]="testPanel.Id + '-' + testPanel.Moniker">
<span class="custom-control-indicator"></span>
</label>
</div>
</ng-template>
</ngb-panel>
这是我要更改复选框的Ts文件
onPanelCheckboxUpdate($event: boolean, panel: TestOrderPanel) {
let testPanelIds = panel.Tests.map(test => test.Id);
// Wipe any duplicates
this.panelIds = this.panelIds.filter(
panelId => panel.Id !== panelId && testPanelIds.indexOf(panelId) === -1
);
this.selectedPanels = this.selectedPanels.filter(
selectedPanel =>
panel.Id !== selectedPanel.Id &&
testPanelIds.indexOf(selectedPanel.Id) === -1
);
if ($event) {
this.panelIds.push(panel.Id);
this.selectedPanels.push(panel);
}
this.updateSession();
}
这是我的应用程序自定义手风琴组件
<div class="card">
<ng-template ngFor let-panel [ngForOf]="panels">
<div role="tab" id="{{panel.id}}-header" [class]="'card-header ' +
(panel.type ? 'card-' + panel.type: type ? 'card-' + type : '')"
[class.active]="isOpen(panel.id)">
<a href (click)="!!toggle(panel.id)" [attr.tabindex]=" .
(panel.disabled
? '-1' : null)" [attr.aria-expanded]="isOpen(panel.id)"
[attr.aria-controls]="(isOpen(panel.id) ? panel.id : null)"
[attr.aria-disabled]="panel.disabled">{{panel.title}}</a>
<ng-template [ngTemplateOutlet]="panel.titleTpl?.templateRef"></ng-
template>
<!-- expansion arrows -->
<div *ngIf="arrowExpand" (click)="toggle(panel.id)" [attr.aria-
expanded]="isOpen(panel.id)">
<span class="material-icons expand"></span>
</div>
</div>
<div id="{{panel.id}}" role="tabpanel" [attr.aria-labelledby]="panel.id + '-header'" class="card-block" *ngIf="isOpen(panel.id) && panel.contentTpl">
<ng-template [ngTemplateOutlet]="panel.contentTpl?.templateRef"></ng-template>
</div>
</ng-template>
</div>
如何在单击复选框时更改整个行的颜色 例如,当选中复选框时,整行应为深色或其他颜色;未选中时应为前一颜色,即白色 有人可以帮忙吗?谢谢
答案 0 :(得分:1)
您可以使用(点击)使整个行可点击:
示例:
<div (click)="someFunction()"></div>
使div
可点击
要基于复选框的值更改颜色,可以启用和禁用将颜色应用于元素的类,如下所示:
<div [className]="valueOfCheckBox? 'example-class' : 'other-class'"></div>
在上面的代码中,valueOfCheckBox
将是您的check-box
的值,而example-class
可以是带有颜色的class
和other-class
可以class
带有颜色,以便在未选中时显示颜色。
您也可以使用style
进行如下操作:
<div [style.color]="valueOfCheckBox ? 'blue' : 'green'"></div>