我是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