Angular updating a list doesn't work after first (seemingly) successful delete
up vote
2
down vote
favorite
I am following the Angular hero tutorial while using Ionic to build a task list. I am at the 'http' part of the tutorial but got stuck at deleting tasks using RxJS.
What happened:
- Swipe on a task, the task is deleted from the view.
- Afterwards, deletion (swipe or click) no longer works with any of the remaining tasks.
- Also, adding a task using a sibling component partially works (as reported by the "message" component), but added tasks no longer show up on the task list.
- Updating any remaining task seemingly still works.
I first suspected it was some conflict with Ionic, but even if I changed the swipe action to normal clicking events, the same thing happens.
Here are the codes for related components. Any help will be much appreciated!
You can find the code here: https://github.com/hktang/butler
tasks.page.html
<ion-header>
<ion-toolbar>
<ion-title>Tasks</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-list>
<app-task-input [tasks]="tasks"></app-task-input>
<app-task-list
[tasks]="tasks"
(selectedTaskChange)="onSelectedTaskChange($event)"
></app-task-list>
</ion-list>
<app-task-detail [task]="selectedTask"></app-task-detail>
<app-messages></app-messages>
</ion-content>
tasks.page.ts
import Component, OnInit from "@angular/core";
import Task from "./task";
import TaskService from "./task.service";
@Component(
selector: "app-tasks",
templateUrl: "./tasks.page.html",
styleUrls: ["./tasks.page.scss"]
)
export class TasksPage implements OnInit
selectedTask: Task;
tasks: Task;
constructor(private taskService: TaskService)
ngOnInit()
this.getTasks();
getTasks(): void
this.taskService.getTasks().subscribe(tasks => (this.tasks = tasks));
onSelectedTaskChange(task: Task): void
this.selectedTask = task;
task.service.ts
import Injectable from "@angular/core";
import HttpClient, HttpHeaders from "@angular/common/http";
import Observable, of from "rxjs";
import Task from "./task";
import MessageService from "../messages/message.service";
import catchError, map, tap from "rxjs/operators";
const httpOptions =
headers: new HttpHeaders( "Content-Type": "application/json" )
;
@Injectable(
providedIn: "root"
)
export class TaskService number): Observable<Task>
const id = typeof task === 'number' ? task : task.id;
const url = `$this.tasksUrl/$id`;
return this.http.delete<Task>(url, httpOptions).pipe(
tap(_ => this.log(`deleted task id=$id`)),
catchError(this.handleError<Task>('deleteTask'))
);
...
task-list.component.html
<ion-list *ngIf="tasks">
<ion-item-sliding
*ngFor="let task of tasks"
(ionSwipe)="markDone(task)">
<ion-item
(click)="onSelect(task)"
[class.selected]="task === selectedTask">
<ion-label>task.name</ion-label>
</ion-item>
<ion-item-options side="right">
<button ion-button (click)="markDone(task)">Done</button>
</ion-item-options>
</ion-item-sliding>
</ion-list>
task-list.component.ts
import Component, EventEmitter, OnInit, Input, Output from "@angular/core";
import Task from "../task";
import TaskService from "../task.service";
@Component(
selector: "app-task-list",
templateUrl: "./task-list.component.html",
styleUrls: ["./task-list.component.scss"]
)
export class TaskListComponent implements OnInit
selectedTask: Task;
@Input()
tasks: Task;
@Output()
selectedTaskChange = new EventEmitter<Task>();
constructor(private taskService: TaskService)
ngOnInit()
onSelect(task: Task): void
this.selectedTask = task;
this.selectedTaskChange.emit(task);
markDone(task: Task)
this.tasks = this.tasks.filter(tsk => tsk !== task);
this.taskService.deleteTask(task).subscribe();
angular ionic-framework
|
show 2 more comments
up vote
2
down vote
favorite
I am following the Angular hero tutorial while using Ionic to build a task list. I am at the 'http' part of the tutorial but got stuck at deleting tasks using RxJS.
What happened:
- Swipe on a task, the task is deleted from the view.
- Afterwards, deletion (swipe or click) no longer works with any of the remaining tasks.
- Also, adding a task using a sibling component partially works (as reported by the "message" component), but added tasks no longer show up on the task list.
- Updating any remaining task seemingly still works.
I first suspected it was some conflict with Ionic, but even if I changed the swipe action to normal clicking events, the same thing happens.
Here are the codes for related components. Any help will be much appreciated!
You can find the code here: https://github.com/hktang/butler
tasks.page.html
<ion-header>
<ion-toolbar>
<ion-title>Tasks</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-list>
<app-task-input [tasks]="tasks"></app-task-input>
<app-task-list
[tasks]="tasks"
(selectedTaskChange)="onSelectedTaskChange($event)"
></app-task-list>
</ion-list>
<app-task-detail [task]="selectedTask"></app-task-detail>
<app-messages></app-messages>
</ion-content>
tasks.page.ts
import Component, OnInit from "@angular/core";
import Task from "./task";
import TaskService from "./task.service";
@Component(
selector: "app-tasks",
templateUrl: "./tasks.page.html",
styleUrls: ["./tasks.page.scss"]
)
export class TasksPage implements OnInit
selectedTask: Task;
tasks: Task;
constructor(private taskService: TaskService)
ngOnInit()
this.getTasks();
getTasks(): void
this.taskService.getTasks().subscribe(tasks => (this.tasks = tasks));
onSelectedTaskChange(task: Task): void
this.selectedTask = task;
task.service.ts
import Injectable from "@angular/core";
import HttpClient, HttpHeaders from "@angular/common/http";
import Observable, of from "rxjs";
import Task from "./task";
import MessageService from "../messages/message.service";
import catchError, map, tap from "rxjs/operators";
const httpOptions =
headers: new HttpHeaders( "Content-Type": "application/json" )
;
@Injectable(
providedIn: "root"
)
export class TaskService number): Observable<Task>
const id = typeof task === 'number' ? task : task.id;
const url = `$this.tasksUrl/$id`;
return this.http.delete<Task>(url, httpOptions).pipe(
tap(_ => this.log(`deleted task id=$id`)),
catchError(this.handleError<Task>('deleteTask'))
);
...
task-list.component.html
<ion-list *ngIf="tasks">
<ion-item-sliding
*ngFor="let task of tasks"
(ionSwipe)="markDone(task)">
<ion-item
(click)="onSelect(task)"
[class.selected]="task === selectedTask">
<ion-label>task.name</ion-label>
</ion-item>
<ion-item-options side="right">
<button ion-button (click)="markDone(task)">Done</button>
</ion-item-options>
</ion-item-sliding>
</ion-list>
task-list.component.ts
import Component, EventEmitter, OnInit, Input, Output from "@angular/core";
import Task from "../task";
import TaskService from "../task.service";
@Component(
selector: "app-task-list",
templateUrl: "./task-list.component.html",
styleUrls: ["./task-list.component.scss"]
)
export class TaskListComponent implements OnInit
selectedTask: Task;
@Input()
tasks: Task;
@Output()
selectedTaskChange = new EventEmitter<Task>();
constructor(private taskService: TaskService)
ngOnInit()
onSelect(task: Task): void
this.selectedTask = task;
this.selectedTaskChange.emit(task);
markDone(task: Task)
this.tasks = this.tasks.filter(tsk => tsk !== task);
this.taskService.deleteTask(task).subscribe();
angular ionic-framework
what error appears?
– Microsmsm
Nov 10 at 1:49
Strangely there's no error message from the console or from the build process. @Microsmsm
– hktang
Nov 10 at 1:51
try an operator by operator like this:import "rxjs/add/operator/map";
– Microsmsm
Nov 10 at 1:54
Thanks @Microsmsm, I haveimport catchError, map, tap from "rxjs/operators";
in thetask.service
, but it is never used. Where should it go..?
– hktang
Nov 10 at 1:57
was you be able to fix the problem?
– Microsmsm
Nov 10 at 2:27
|
show 2 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am following the Angular hero tutorial while using Ionic to build a task list. I am at the 'http' part of the tutorial but got stuck at deleting tasks using RxJS.
What happened:
- Swipe on a task, the task is deleted from the view.
- Afterwards, deletion (swipe or click) no longer works with any of the remaining tasks.
- Also, adding a task using a sibling component partially works (as reported by the "message" component), but added tasks no longer show up on the task list.
- Updating any remaining task seemingly still works.
I first suspected it was some conflict with Ionic, but even if I changed the swipe action to normal clicking events, the same thing happens.
Here are the codes for related components. Any help will be much appreciated!
You can find the code here: https://github.com/hktang/butler
tasks.page.html
<ion-header>
<ion-toolbar>
<ion-title>Tasks</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-list>
<app-task-input [tasks]="tasks"></app-task-input>
<app-task-list
[tasks]="tasks"
(selectedTaskChange)="onSelectedTaskChange($event)"
></app-task-list>
</ion-list>
<app-task-detail [task]="selectedTask"></app-task-detail>
<app-messages></app-messages>
</ion-content>
tasks.page.ts
import Component, OnInit from "@angular/core";
import Task from "./task";
import TaskService from "./task.service";
@Component(
selector: "app-tasks",
templateUrl: "./tasks.page.html",
styleUrls: ["./tasks.page.scss"]
)
export class TasksPage implements OnInit
selectedTask: Task;
tasks: Task;
constructor(private taskService: TaskService)
ngOnInit()
this.getTasks();
getTasks(): void
this.taskService.getTasks().subscribe(tasks => (this.tasks = tasks));
onSelectedTaskChange(task: Task): void
this.selectedTask = task;
task.service.ts
import Injectable from "@angular/core";
import HttpClient, HttpHeaders from "@angular/common/http";
import Observable, of from "rxjs";
import Task from "./task";
import MessageService from "../messages/message.service";
import catchError, map, tap from "rxjs/operators";
const httpOptions =
headers: new HttpHeaders( "Content-Type": "application/json" )
;
@Injectable(
providedIn: "root"
)
export class TaskService number): Observable<Task>
const id = typeof task === 'number' ? task : task.id;
const url = `$this.tasksUrl/$id`;
return this.http.delete<Task>(url, httpOptions).pipe(
tap(_ => this.log(`deleted task id=$id`)),
catchError(this.handleError<Task>('deleteTask'))
);
...
task-list.component.html
<ion-list *ngIf="tasks">
<ion-item-sliding
*ngFor="let task of tasks"
(ionSwipe)="markDone(task)">
<ion-item
(click)="onSelect(task)"
[class.selected]="task === selectedTask">
<ion-label>task.name</ion-label>
</ion-item>
<ion-item-options side="right">
<button ion-button (click)="markDone(task)">Done</button>
</ion-item-options>
</ion-item-sliding>
</ion-list>
task-list.component.ts
import Component, EventEmitter, OnInit, Input, Output from "@angular/core";
import Task from "../task";
import TaskService from "../task.service";
@Component(
selector: "app-task-list",
templateUrl: "./task-list.component.html",
styleUrls: ["./task-list.component.scss"]
)
export class TaskListComponent implements OnInit
selectedTask: Task;
@Input()
tasks: Task;
@Output()
selectedTaskChange = new EventEmitter<Task>();
constructor(private taskService: TaskService)
ngOnInit()
onSelect(task: Task): void
this.selectedTask = task;
this.selectedTaskChange.emit(task);
markDone(task: Task)
this.tasks = this.tasks.filter(tsk => tsk !== task);
this.taskService.deleteTask(task).subscribe();
angular ionic-framework
I am following the Angular hero tutorial while using Ionic to build a task list. I am at the 'http' part of the tutorial but got stuck at deleting tasks using RxJS.
What happened:
- Swipe on a task, the task is deleted from the view.
- Afterwards, deletion (swipe or click) no longer works with any of the remaining tasks.
- Also, adding a task using a sibling component partially works (as reported by the "message" component), but added tasks no longer show up on the task list.
- Updating any remaining task seemingly still works.
I first suspected it was some conflict with Ionic, but even if I changed the swipe action to normal clicking events, the same thing happens.
Here are the codes for related components. Any help will be much appreciated!
You can find the code here: https://github.com/hktang/butler
tasks.page.html
<ion-header>
<ion-toolbar>
<ion-title>Tasks</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-list>
<app-task-input [tasks]="tasks"></app-task-input>
<app-task-list
[tasks]="tasks"
(selectedTaskChange)="onSelectedTaskChange($event)"
></app-task-list>
</ion-list>
<app-task-detail [task]="selectedTask"></app-task-detail>
<app-messages></app-messages>
</ion-content>
tasks.page.ts
import Component, OnInit from "@angular/core";
import Task from "./task";
import TaskService from "./task.service";
@Component(
selector: "app-tasks",
templateUrl: "./tasks.page.html",
styleUrls: ["./tasks.page.scss"]
)
export class TasksPage implements OnInit
selectedTask: Task;
tasks: Task;
constructor(private taskService: TaskService)
ngOnInit()
this.getTasks();
getTasks(): void
this.taskService.getTasks().subscribe(tasks => (this.tasks = tasks));
onSelectedTaskChange(task: Task): void
this.selectedTask = task;
task.service.ts
import Injectable from "@angular/core";
import HttpClient, HttpHeaders from "@angular/common/http";
import Observable, of from "rxjs";
import Task from "./task";
import MessageService from "../messages/message.service";
import catchError, map, tap from "rxjs/operators";
const httpOptions =
headers: new HttpHeaders( "Content-Type": "application/json" )
;
@Injectable(
providedIn: "root"
)
export class TaskService number): Observable<Task>
const id = typeof task === 'number' ? task : task.id;
const url = `$this.tasksUrl/$id`;
return this.http.delete<Task>(url, httpOptions).pipe(
tap(_ => this.log(`deleted task id=$id`)),
catchError(this.handleError<Task>('deleteTask'))
);
...
task-list.component.html
<ion-list *ngIf="tasks">
<ion-item-sliding
*ngFor="let task of tasks"
(ionSwipe)="markDone(task)">
<ion-item
(click)="onSelect(task)"
[class.selected]="task === selectedTask">
<ion-label>task.name</ion-label>
</ion-item>
<ion-item-options side="right">
<button ion-button (click)="markDone(task)">Done</button>
</ion-item-options>
</ion-item-sliding>
</ion-list>
task-list.component.ts
import Component, EventEmitter, OnInit, Input, Output from "@angular/core";
import Task from "../task";
import TaskService from "../task.service";
@Component(
selector: "app-task-list",
templateUrl: "./task-list.component.html",
styleUrls: ["./task-list.component.scss"]
)
export class TaskListComponent implements OnInit
selectedTask: Task;
@Input()
tasks: Task;
@Output()
selectedTaskChange = new EventEmitter<Task>();
constructor(private taskService: TaskService)
ngOnInit()
onSelect(task: Task): void
this.selectedTask = task;
this.selectedTaskChange.emit(task);
markDone(task: Task)
this.tasks = this.tasks.filter(tsk => tsk !== task);
this.taskService.deleteTask(task).subscribe();
angular ionic-framework
angular ionic-framework
edited Nov 14 at 12:13
asked Nov 10 at 1:46
hktang
8701329
8701329
what error appears?
– Microsmsm
Nov 10 at 1:49
Strangely there's no error message from the console or from the build process. @Microsmsm
– hktang
Nov 10 at 1:51
try an operator by operator like this:import "rxjs/add/operator/map";
– Microsmsm
Nov 10 at 1:54
Thanks @Microsmsm, I haveimport catchError, map, tap from "rxjs/operators";
in thetask.service
, but it is never used. Where should it go..?
– hktang
Nov 10 at 1:57
was you be able to fix the problem?
– Microsmsm
Nov 10 at 2:27
|
show 2 more comments
what error appears?
– Microsmsm
Nov 10 at 1:49
Strangely there's no error message from the console or from the build process. @Microsmsm
– hktang
Nov 10 at 1:51
try an operator by operator like this:import "rxjs/add/operator/map";
– Microsmsm
Nov 10 at 1:54
Thanks @Microsmsm, I haveimport catchError, map, tap from "rxjs/operators";
in thetask.service
, but it is never used. Where should it go..?
– hktang
Nov 10 at 1:57
was you be able to fix the problem?
– Microsmsm
Nov 10 at 2:27
what error appears?
– Microsmsm
Nov 10 at 1:49
what error appears?
– Microsmsm
Nov 10 at 1:49
Strangely there's no error message from the console or from the build process. @Microsmsm
– hktang
Nov 10 at 1:51
Strangely there's no error message from the console or from the build process. @Microsmsm
– hktang
Nov 10 at 1:51
try an operator by operator like this:
import "rxjs/add/operator/map";
– Microsmsm
Nov 10 at 1:54
try an operator by operator like this:
import "rxjs/add/operator/map";
– Microsmsm
Nov 10 at 1:54
Thanks @Microsmsm, I have
import catchError, map, tap from "rxjs/operators";
in the task.service
, but it is never used. Where should it go..?– hktang
Nov 10 at 1:57
Thanks @Microsmsm, I have
import catchError, map, tap from "rxjs/operators";
in the task.service
, but it is never used. Where should it go..?– hktang
Nov 10 at 1:57
was you be able to fix the problem?
– Microsmsm
Nov 10 at 2:27
was you be able to fix the problem?
– Microsmsm
Nov 10 at 2:27
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
changing the code of showing tasks to just this should fix the problem
<ion-item-sliding *ngFor="let task of tasks" (ionSwipe)="markDone(task)">
<ion-item>task.name</ion-item>
<ion-item-options> </ion-item-options>
</ion-item-sliding>
Thanks for your help, this works. I also found my original code was using ionic3 but I am using ionic 4. Now the problem is, I can add tasks, but the task doesn't show up (after making delete action).
– hktang
Nov 10 at 10:18
Also I don't understand why adding an <ionic-item-option> inside the "options" group breaks the code..?
– hktang
Nov 10 at 10:22
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
changing the code of showing tasks to just this should fix the problem
<ion-item-sliding *ngFor="let task of tasks" (ionSwipe)="markDone(task)">
<ion-item>task.name</ion-item>
<ion-item-options> </ion-item-options>
</ion-item-sliding>
Thanks for your help, this works. I also found my original code was using ionic3 but I am using ionic 4. Now the problem is, I can add tasks, but the task doesn't show up (after making delete action).
– hktang
Nov 10 at 10:18
Also I don't understand why adding an <ionic-item-option> inside the "options" group breaks the code..?
– hktang
Nov 10 at 10:22
add a comment |
up vote
1
down vote
changing the code of showing tasks to just this should fix the problem
<ion-item-sliding *ngFor="let task of tasks" (ionSwipe)="markDone(task)">
<ion-item>task.name</ion-item>
<ion-item-options> </ion-item-options>
</ion-item-sliding>
Thanks for your help, this works. I also found my original code was using ionic3 but I am using ionic 4. Now the problem is, I can add tasks, but the task doesn't show up (after making delete action).
– hktang
Nov 10 at 10:18
Also I don't understand why adding an <ionic-item-option> inside the "options" group breaks the code..?
– hktang
Nov 10 at 10:22
add a comment |
up vote
1
down vote
up vote
1
down vote
changing the code of showing tasks to just this should fix the problem
<ion-item-sliding *ngFor="let task of tasks" (ionSwipe)="markDone(task)">
<ion-item>task.name</ion-item>
<ion-item-options> </ion-item-options>
</ion-item-sliding>
changing the code of showing tasks to just this should fix the problem
<ion-item-sliding *ngFor="let task of tasks" (ionSwipe)="markDone(task)">
<ion-item>task.name</ion-item>
<ion-item-options> </ion-item-options>
</ion-item-sliding>
<ion-item-sliding *ngFor="let task of tasks" (ionSwipe)="markDone(task)">
<ion-item>task.name</ion-item>
<ion-item-options> </ion-item-options>
</ion-item-sliding>
<ion-item-sliding *ngFor="let task of tasks" (ionSwipe)="markDone(task)">
<ion-item>task.name</ion-item>
<ion-item-options> </ion-item-options>
</ion-item-sliding>
edited Nov 10 at 4:46
answered Nov 10 at 2:02
Microsmsm
1,8871624
1,8871624
Thanks for your help, this works. I also found my original code was using ionic3 but I am using ionic 4. Now the problem is, I can add tasks, but the task doesn't show up (after making delete action).
– hktang
Nov 10 at 10:18
Also I don't understand why adding an <ionic-item-option> inside the "options" group breaks the code..?
– hktang
Nov 10 at 10:22
add a comment |
Thanks for your help, this works. I also found my original code was using ionic3 but I am using ionic 4. Now the problem is, I can add tasks, but the task doesn't show up (after making delete action).
– hktang
Nov 10 at 10:18
Also I don't understand why adding an <ionic-item-option> inside the "options" group breaks the code..?
– hktang
Nov 10 at 10:22
Thanks for your help, this works. I also found my original code was using ionic3 but I am using ionic 4. Now the problem is, I can add tasks, but the task doesn't show up (after making delete action).
– hktang
Nov 10 at 10:18
Thanks for your help, this works. I also found my original code was using ionic3 but I am using ionic 4. Now the problem is, I can add tasks, but the task doesn't show up (after making delete action).
– hktang
Nov 10 at 10:18
Also I don't understand why adding an <ionic-item-option> inside the "options" group breaks the code..?
– hktang
Nov 10 at 10:22
Also I don't understand why adding an <ionic-item-option> inside the "options" group breaks the code..?
– hktang
Nov 10 at 10:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235338%2fangular-updating-a-list-doesnt-work-after-first-seemingly-successful-delete%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what error appears?
– Microsmsm
Nov 10 at 1:49
Strangely there's no error message from the console or from the build process. @Microsmsm
– hktang
Nov 10 at 1:51
try an operator by operator like this:
import "rxjs/add/operator/map";
– Microsmsm
Nov 10 at 1:54
Thanks @Microsmsm, I have
import catchError, map, tap from "rxjs/operators";
in thetask.service
, but it is never used. Where should it go..?– hktang
Nov 10 at 1:57
was you be able to fix the problem?
– Microsmsm
Nov 10 at 2:27