Skip to content

Commit 1a09a9e

Browse files
committed
refactor(icon.directive): host binding innerHtml
1 parent 13f6548 commit 1a09a9e

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

projects/coreui-icons-angular/src/lib/icon/icon.directive.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { transformName } from './icon.utils';
88
@Directive({
99
exportAs: 'cIcon',
1010
selector: 'svg[cIcon]',
11-
standalone: true
11+
standalone: true,
12+
host: { ngSkipHydration: 'true', '[innerHtml]': 'innerHtml()' }
1213
})
1314
export class IconDirective implements IIcon {
1415
readonly #elementRef = inject(ElementRef);
@@ -78,13 +79,8 @@ export class IconDirective implements IIcon {
7879
return this.computedClasses;
7980
}
8081

81-
@HostBinding('innerHtml')
82-
get bindInnerHtml() {
83-
return this.innerHtml();
84-
}
85-
8682
readonly innerHtml = computed(() => {
87-
const code = Array.isArray(this.code()) ? this.code()[1] ?? this.code()[0] ?? '' : this.code() || '';
83+
const code = Array.isArray(this.code()) ? (this.code()[1] ?? this.code()[0] ?? '') : this.code() || '';
8884
// todo proper sanitize
8985
// const sanitized = this.sanitizer.sanitize(SecurityContext.HTML, code);
9086
return this.#sanitizer.bypassSecurityTrustHtml(this.titleCode + code || '');
@@ -103,16 +99,15 @@ export class IconDirective implements IIcon {
10399
}
104100
if (this.#name() && !this.#iconSet?.icons[this.#name()]) {
105101
console.warn(
106-
`c-icon component: icon name '${this.#name()}' does not exist for IconSet service. ` +
107-
`To use icon by 'name' prop you need to add it to IconSet service. \n`,
102+
`cIcon directive: The '${this.#name()}' icon not found. Add it to the IconSet service for use with the 'name' property. \n`,
108103
this.#name()
109104
);
110105
}
111106
return '';
112107
});
113108

114109
readonly scale = computed(() => {
115-
return Array.isArray(this.code()) && this.code().length > 1 ? `0 0 ${this.code()[0]}` : '0 0 64 64';
110+
return Array.isArray(this.code()) && (this.code()?.length ?? 0) > 1 ? `0 0 ${this.code()?.[0]}` : '0 0 64 64';
116111
});
117112

118113
get computedSize(): Exclude<IconSize, 'custom'> | undefined {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy