From 84ec1620a89e4efdfc12269be48e0e2028098eb6 Mon Sep 17 00:00:00 2001 From: Karsa Date: Thu, 20 Apr 2023 18:25:18 +0200 Subject: [PATCH] [lucide-angular] Fixes change detection issue with legacy `img` input setter (#1129) * [lucide-angular] Fixes img setter alias * fixes change detection issue with img setter --------- Co-authored-by: Karsa --- .../src/lib/lucide-angular.component.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/lucide-angular/src/lib/lucide-angular.component.ts b/packages/lucide-angular/src/lib/lucide-angular.component.ts index a5aaa13d3..af9611b93 100644 --- a/packages/lucide-angular/src/lib/lucide-angular.component.ts +++ b/packages/lucide-angular/src/lib/lucide-angular.component.ts @@ -11,6 +11,7 @@ interface TypedChange extends SimpleChange { type LucideAngularComponentChanges = { name?: TypedChange; + img?: TypedChange; color?: TypedChange; size?: TypedChange; strokeWidth?: TypedChange; @@ -30,7 +31,7 @@ export class LucideAngularComponent implements OnChanges { @Input() name?: string|LucideIconData; @Input() set img(img: LucideIconData) { this.name = img; - } + }; @Input() color?: string; _size?: number; get size(): number { @@ -70,8 +71,8 @@ export class LucideAngularComponent implements OnChanges { this.strokeWidth ?? this.iconConfig.strokeWidth ); this.absoluteStrokeWidth = this.absoluteStrokeWidth ?? false; - if (changes.name) { - const name = changes.name.currentValue; + if (changes.name || changes.img) { + const name = changes.img?.currentValue ?? changes.name?.currentValue; if (typeof name === 'string') { const icoOfName = this.getIcon(this.toPascalCase(name)); if (icoOfName) { @@ -79,8 +80,10 @@ export class LucideAngularComponent implements OnChanges { } else { throw new Error(`The "${name}" icon has not been provided by any available icon providers.`); } - } else { + } else if (typeof name === 'object') { this.replaceElement(name); + } else { + throw new Error(`No icon name or image has been provided.`); } }