From 5b3d0c46dd7971a97cfde0e95a904848d6dec1f6 Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Sat, 23 May 2020 20:23:22 +0530 Subject: [PATCH] fix: has-permission directive for OnChanges (#795) Fixes: #794 --- .../directives/has-permission/has-permission.directive.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/app/directives/has-permission/has-permission.directive.ts b/src/app/directives/has-permission/has-permission.directive.ts index 63c5ec812..145ff7e0b 100644 --- a/src/app/directives/has-permission/has-permission.directive.ts +++ b/src/app/directives/has-permission/has-permission.directive.ts @@ -36,12 +36,11 @@ export class HasPermissionDirective { if (typeof permission !== 'string') { throw new Error('hasPermission value must be a string'); } + /** Clear the template beforehand to prevent overlap OnChanges. */ + this.viewContainer.clear(); + /** Shows Template if user has permission */ if (this.hasPermission(permission)) { - /** Shows Template */ this.viewContainer.createEmbeddedView(this.templateRef); - } else { - /** Hides Template */ - this.viewContainer.clear(); } }