fix(ivy): resolve enum values in host bindings (#28523)
Some applications use enum values in their host bindings: @Component({ host: { '[prop]': EnumType.Key, }, ... }) This commit changes the resolution of host properties to follow the enum declaration and extract the correct value for the binding. PR Close #28523
This commit is contained in:

committed by
Misko Hevery

parent
09af7ea4f5
commit
3477610f6d
@ -1004,6 +1004,31 @@ describe('ngtsc behavioral tests', () => {
|
||||
expect(trim(jsContents)).toContain(trim(hostBindingsFn));
|
||||
});
|
||||
|
||||
it('should accept enum values as host bindings', () => {
|
||||
env.tsconfig();
|
||||
env.write(`test.ts`, `
|
||||
import {Component, HostBinding, HostListener, TemplateRef} from '@angular/core';
|
||||
|
||||
enum HostBindings {
|
||||
Hello = 'foo'
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'test',
|
||||
template: 'Test',
|
||||
host: {
|
||||
'[attr.hello]': HostBindings.Hello,
|
||||
},
|
||||
})
|
||||
class FooCmp {
|
||||
foo = 'test';
|
||||
}
|
||||
`);
|
||||
|
||||
env.driveMain();
|
||||
expect(env.getContents('test.js')).toContain('"hello", i0.ɵbind(ctx.foo)');
|
||||
});
|
||||
|
||||
it('should generate host listeners for directives within hostBindings section', () => {
|
||||
env.tsconfig();
|
||||
env.write(`test.ts`, `
|
||||
|
Reference in New Issue
Block a user