From a2e6ee4c9550a9148b9c756cc3066465c3cb2796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Popovics=20Andr=C3=A1s?= Date: Thu, 23 Nov 2017 19:44:18 +0000 Subject: [PATCH] Fix Like component to be reactive on change of nodeId parameter (#2717) --- lib/content-services/social/like.component.spec.ts | 2 ++ lib/content-services/social/like.component.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/content-services/social/like.component.spec.ts b/lib/content-services/social/like.component.spec.ts index 1b3ebc2f7f..c21e447ec6 100644 --- a/lib/content-services/social/like.component.spec.ts +++ b/lib/content-services/social/like.component.spec.ts @@ -60,6 +60,8 @@ describe('Like component', () => { } it('should load the likes by default on onChanges', async(() => { + component.ngOnChanges(); + simulateResponseWithLikes(2); fixture.whenStable().then(() => { diff --git a/lib/content-services/social/like.component.ts b/lib/content-services/social/like.component.ts index 8d69474d20..50d143dab4 100644 --- a/lib/content-services/social/like.component.ts +++ b/lib/content-services/social/like.component.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; +import { Component, EventEmitter, Input, OnChanges, Output, ViewEncapsulation } from '@angular/core'; import { RatingService } from './services/rating.service'; @Component({ @@ -25,7 +25,7 @@ import { RatingService } from './services/rating.service'; providers: [RatingService], encapsulation: ViewEncapsulation.None }) -export class LikeComponent implements OnInit { +export class LikeComponent implements OnChanges { @Input() nodeId: string; @@ -39,7 +39,7 @@ export class LikeComponent implements OnInit { constructor(private ratingService: RatingService) {} - ngOnInit() { + ngOnChanges() { this.clean(); this.ratingService.getRating(this.nodeId, this.ratingType).subscribe(