我是Angular的新手,我想獲取當前選中的複選框ID。我已經檢查過其他線程,但其中大部分都使用Controller,我正在使用組件。
以下是詳細信息。 我有這樣一個組件角4組件獲取選中複選框
<table class='table table-striped table-hover admin-form' *ngIf="deviceCategories">
<a (click)="test()">test</a>
<thead>
<tr>
<td class="text-center">序列</td>
<th class="text-center">組名</th>
<th class="text-center">LOGO</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let deviceCategory of deviceCategories | paginate: config">
<td class="center">
<input type="checkbox" ng-model="selected[deviceCategory.id]" id="checkbox_{{deviceCategory.id}}">
</td>
<td class="text-center">{{deviceCategory.id}}</td>
<td class="text-center">{{deviceCategory.name}}</td>
<td class="text-center"><img src="{{deviceCategory.logoUrl}}" width="30" alt=""></td>
<td class="text-center project-actions">
<a [routerLink]="['/management/deviceCategory/edit/',deviceCategory.id]" class="btn btn-white btn-xs text-muted"> <i class="fa fa-eye text-system"></i> 修改 </a>
<a (click)="OnDelete(deviceCategory.id)" class="btn btn-white btn-xs text-muted"> <i class="fa fa-eye text-system"></i> 刪除 </a>
</td>
</tr>
</tbody>
這裏是我的TS
import { Component, OnInit, Input } from '@angular/core';
import { PaginationInstance } from 'ng2-pagination';
import { DeviceCategoryService}from '../../../services/deviceCategory.service';
import { DeviceCategoryViewModel } from "../../../model/deviceCategory";
@Component({
selector: 'app-device-category-admin-table',
templateUrl: './device-category-admin-table.component.html',
styleUrls: ['./device-category-admin-table.component.css'],
providers:[DeviceCategoryService]
})
export class DeviceCategoryAdminTableComponent implements OnInit {
@Input() deviceCategories :any;
@Input() config:any;
public selected:{}
constructor(
private deviceCategorySvc:DeviceCategoryService
) { }
ngOnInit() {
}
OnDelete(id:number){
this.deviceCategorySvc.deleteDeviceCategory(id).subscribe(result=>{
if(result.ok)
{
this.deviceCategorySvc.currentCategorys().subscribe(result=>{
this.deviceCategories=result.data as DeviceCategoryViewModel[];
});
}
});
}
test(){
var result=this.selected;
console.log(result);
}
任何幫助,將不勝感激。
哪裏是複選框 – Sajeetharan
感謝,我加入了,現在,我想選擇的deviceCategory.id或deviceCategory –
的旁註:您還使用'NG-model'其中AngularJS語法,也許檢查你的代碼,你實際上沒有在其他地方使用AngularJS語法... – Alex