使用 Angular 和 Angular Material 重写 MediaMan
1. 服务方法的实现
在这部分,我们主要实现了几个关键的服务方法,包括移除书籍集合、创建书籍和移除书籍。
- 移除书籍集合(removeBookCollection)
removeBookCollection(identifier: string): void {
if (!identifier) {
throw new Error('An identifier must be provided');
}
this._bookCollections.delete(identifier);
this.removeMediaCollection(identifier).then(() => {
console.log('Removed the collection with identifier: ', identifier);
}).catch(_ => {
this.displayErrorMessage('Failed to remove the collection!');
});
}
该方法首先检查是否提供了标识符,如果没有则抛出错误。然后从 _bookCollections
中删除对应的集合,并调用 removeMediaCollection
方法移除媒体集合。成功移除后会在控制台打印信息,失败则显示错误