Skip to content

Commit f20a82e

Browse files
committed
Fixed saveBook caused book.list problem.
1 parent ff7b92e commit f20a82e

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/app/home/components/book-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<mat-card class="book-card">
66
<ion-badge color="warning"
77
style="position: absolute; right: -5px; top: -10px;"
8-
*ngIf="book.recordList">
8+
*ngIf="book.recordList && book.recordList.length > 0">
99
{{book.recordList.length}}次阅读
1010
</ion-badge>
1111
<mat-card-title>{{book.name | uppercase}}</mat-card-title>

src/app/home/services/book.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class BookService {
4545
// `deleted` 是可选参数,没有时是 `undefined`, `!undefined`为真,传入`true`时`!true`为假
4646
listUpdated = (book: Book, deleted?: boolean) => {
4747
const index = this.list.findIndex(b => b.id === book.id);
48-
this.list.splice(index, 1);
48+
if(index >= 0) this.list.splice(index, 1);
4949
if(!deleted) this.list.push(book);
5050

5151
const msg: IMessage = {
@@ -74,6 +74,7 @@ export class BookService {
7474
newBook.website = await this.website.newWebsit(site);
7575
newBook.writer = await this.writer.newWriter(writerName, newBook.website);
7676
newBook.cateList = await this.cate.saveList(res.cateList);
77+
newBook.recordList = [];
7778

7879
const query: IQuery = {
7980
table: 'Book',

0 commit comments

Comments
 (0)