Why not updated the interface, after removal of the element?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
23 views
I send the post ID from a child component to the parent, where turning to the service to remove an item, check in the console the items are deleted, but the changes are not visible in the interface. In the method of deletion request to the service, make new posts.
Please help to solve this problem and understand what I'm doing wrong

TS child component:
@Output() remove: EventEmitter = new EventEmitter(); removePost(picId: number): void { this.remove.emit(picId); }

Template child feature:
test

{{pic.id}}:{{pic.title}}


TS parent component:
export class GalleryComponent implements OnInit { collection: Picture[]; constructor(private galleryService: GalleryService) {} ngOnInit() { this.collection = this.galleryService.getPictures(); } removePost(picId: number): void { this.galleryService.remove(picId); this.collection = this.galleryService.getPictures(); }

The template of the parent component:

Service:
import { Injectable } from '@angular/core'; import { myCollection } from './gallery-data'; import {Picture} from "./gallery-module/gallery/Picture"; @Injectable({ providedIn: 'root' }) export class GalleryService { Mycollection: Picture[] = myCollection; constructor() { } getPictures(): Picture[] { return (myCollection); } remove(picId: number): Picture[] { return this.Mycollection = this.Mycollection .filter(p => p.id !== picId); } }
by | 23 views

2 Answers

0 like 0 dislike
After removal of the element you are requesting the source data - a method getPictures instead of this.Returns Mycollection myCollection (by the way, and the normal names had to come up with any way? - without this ugly my and to upper case was used more, m-m-m, uniformly).
by
0 like 0 dislike
you have service because it always returns the same collection, and have this.Mycollection
getPictures(): Picture[] { return (myCollection); }
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
36,634 users