-3
得到了一個模板:更改單擊角2
<table class="table table-sm" style="background-color: lightgrey;">
<tbody>
<tr *ngFor="let category of categories">
<td class="central">
<p>{{category.categoryName}}</p>
<!--<input class="form-control" value="{{category.categoryName}}">-->
</td>
<td><button type="button" class="btn btn-outline-warning">Edit</button></td>
<td><button type="button" class="btn btn-outline-danger">Delete</button></td>
<!--<td><button type="button" class="btn btn-outline-warning">Done</button></td>-->
<!--<td><button type="button" class="btn btn-outline-danger">Cancel</button></td>-->
</tr>
</tbody>
</table>
帶*號ngFor指令我dinamically創建在第一列的表,其中有一些類別的名稱(每個也有categoryId字段),第二列有編輯按鈕,第三個 - 刪除按鈕。
我想要有下一個功能:當用戶點擊編輯按鈕在其行中帶有類別名稱的p元素需要被具有類別名稱值的輸入元素替換時,編輯和刪除按鈕也需要被替換與完成和取消按鈕。單擊「編輯」按鈕即可更改該行。
得到了類別下一個模型:
export class Category {
constructor(
public categoryId: number,
public categoryName: string
){}
}
這裏是組件文件的一部分:
import {Component, OnInit} from '@angular/core';
import {Category} from "./models/category";
import {CategoryService} from "./category.service";
@Component({
selector: 'my-categories',
templateUrl: './categories.component.html',
})
export class CategoriesComponent implements OnInit{
categories: Category[];
constructor (private categoryService: CategoryService) {}
ngOnInit() {
this.getCategories();
}
...
請向我們展示您嘗試的內容。 –
我想過將所有元素添加到DOM中,並且其中一些隱藏了ng樣式。但不知道如何才能讓按鈕點擊某些元素並更改樣式以顯示它們,然後獲取一些元素來隱藏它們/ –
從簡單的開始 - 使用靜態數據獲得一行效果 –