From 7f357ddde0586fa8fd64655416c0b12d3df49877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 4 Jan 2019 17:03:55 +0100 Subject: [PATCH] MOBILE-2795 comments: Detect changes on component --- .../comments/components/comments/comments.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/core/comments/components/comments/comments.ts b/src/core/comments/components/comments/comments.ts index 657848984..079716675 100644 --- a/src/core/comments/components/comments/comments.ts +++ b/src/core/comments/components/comments/comments.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input } from '@angular/core'; +import { Component, Input, OnChanges, SimpleChange } from '@angular/core'; import { NavParams, NavController } from 'ionic-angular'; import { CoreCommentsProvider } from '../../providers/comments'; @@ -23,7 +23,7 @@ import { CoreCommentsProvider } from '../../providers/comments'; selector: 'core-comments', templateUrl: 'core-comments.html', }) -export class CoreCommentsCommentsComponent { +export class CoreCommentsCommentsComponent implements OnChanges { @Input() contextLevel: string; @Input() instanceId: number; @Input() component: string; @@ -41,6 +41,22 @@ export class CoreCommentsCommentsComponent { * View loaded. */ ngOnInit(): void { + this.fetchData(); + } + + /** + * Listen to changes. + */ + ngOnChanges(changes: { [name: string]: SimpleChange }): void { + // If something change, update the fields. + if (changes) { + this.fetchData(); + } + } + + protected fetchData(): void { + this.commentsLoaded = false; + this.commentsProvider.getComments(this.contextLevel, this.instanceId, this.component, this.itemId, this.area, this.page) .then((comments) => { this.commentsCount = comments && comments.length ? comments.length : 0;