2017-06-02 43 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

相關問題