2017-06-02 69 views
0

我有一个包含数据的表格,而我的最后一个单元格是一个删除按钮,可以删除一行。Angular2可点击的表行,除了最后一个单元格

我面临的问题是,我的行是可点击的,它带我到另一个页面来编辑元素,所以当我点击删除按钮时,它删除元素,但也带我到编辑页面。

这里是我的代码:

<table class="data-table-format"> 
    <thead> 
    <tr> 
     <th>id</th> 
     <th>Maker</th> 
     <th>Model</th> 
     <th>Year</th> 
     <th></th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr *ngFor="let car of pagedItems" (click)="editCar(car)"> 
     <th>{{ car.car_id }}</th> 
     <td>{{ car.car_maker }}</td> 
     <td>{{ car.car_model }}</td> 
     <td>{{ car.car_year }}</td> 
     <td><i class="material-icons" style="color:red" (click)="deleteCar(car.car_id)">delete_forever</i></td> 
    </tr> 
    </tbody> 
</table> 

如何与角/打字稿做什么建议吗?

+3

你尝试过'event.stopPropagation();'? – echonax

+0

是jQuery吗?我想避免jQuery,如果有可能 –

+2

DUPLICATE问题[在这里回答](https://stackoverflow.com/questions/20300866/angularjs-ng-click-stoppropagation) –

回答

4

你可以试试这个。这不是jQuery

<tbody> 
    <tr *ngFor="let car of pagedItems" (click)="editCar(car)"> 
     <th>{{ car.car_id }}</th> 
     <td>{{ car.car_maker }}</td> 
     <td>{{ car.car_model }}</td> 
     <td>{{ car.car_year }}</td> 
     <td><i class="material-icons" style="color:red" (click)="$event.stopPropagation();deleteCar(car.car_id)">delete_forever</i></td> 
    </tr> 
    </tbody> 
+0

谢谢你完美的工作 –

+2

@sainu这已经在评论中解决,这是一个重复的问题。感谢你的付出。 –

+0

正是我需要的。谢谢 – jgritten

相关问题