New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combination of HostBinding
and signals is not supported (input signals too)
#53888
Comments
My initial thought is that |
It's also possible to split the two, and write: appModalClose = input.required<string>();
@HostBinding('attr.title')
get title() { return this.appModalClose(); } |
Thanks again for this issue. I've chatted a little with @pkozlowski-opensource and we both felt like supporting
You mentioned something with memory leak when using @Directive({
standalone: true,
selector: 'my-dirx',
host: { '[attr.title]': 'bla()' },
})
export class MyDir {
bla = input.required<string>();
} |
@devversion I have doubble checked @Directive({
standalone: true,
selector: 'my-dirx',
host: { '[attr.title]': 'bla()' },
})
export class MyDir {
bla = input.required<string>();
} and it is working right now |
HostBinding
and singals is not supported (input signals too)
HostBinding
and singals is not supported (input signals too)HostBinding
and signals is not supported (input signals too)
Oh, so we're stuck with using a string expression with no IDE support? That's unfortunate. |
@cyraid Which IDE do you use? I am using WebStorm, and it works like a charm, with code highlighting, suggestions and everything. |
@dkimmich-onventis I use vscode. It would be nice if angular highlighted and syntax/error checked the host field in vscode. :) |
Why is the syntax
instead of
which would make more sense to me. In other words: why is the value a string? Just wondering. |
Because |
There is no reference named |
If this is going to be the recommended approach going forward, should this style guide rule be updated? |
@nickdobson Yeah, we likely need to discuss this more with the team. Good point. |
@devversion has a function in the constructor been considered? constructor() {
hostBinding('class.hidden', () => this.isHidden());
hostBinding('class.hidden', this.isHidden); // alternative: isHidden is a signal
} |
I like having hostBinding and hostListener functions more, than using not recommended by style guide host property of directive decorator. |
@k3nsei As mentionned in #54284, the style guide is know to be a bit outdated on some topics. As mentionned here, the host property is being recommended over the usage of the hostBinding/hostListener. |
@JeanMeche but HostBinding and HostListener are working with class inheritance. We are using that in our FormControl abstractions to not repeat code.That means regression in some way, because class decorators are not inherited. We mostly need to do that, to not copy/paste code to use custom form controls inside angular material form field, as it's requires a lot of stuff to be implemented in custom form control. We could of course use some mix of hostDirectives and base abstract class which delegates methods and getters and setters calls to this directives basically works as a proxy. But this sounds like a hack to me. |
@JeanMeche I've noticted the recommendation on the angular.dev website is conflicting with the angular.io styleguide, as it stills recommends I was wondering why the Should the styleguide be updated? |
@shajz |
Thanks for pointing it out but that was not my main point, merely a nudge in understanding the issue. Sorry if my message was misunderstood: The problem I highlighted is that both the official Angular websites conflict on the recommendation of using host vs HostBinding/HostListener. That should be addressed on the angular repo :) |
The style guide will be updated as part of the upcoming v18 release. This is tracked by ##54284. |
@JeanMeche could this release also be synchronized with folks from |
@k3nsei angular-eslint/angular-eslint#1772 I've suggested the change, thank you. |
I like this suggestion
or event something like this @Component({/*...*/})
export class Component {
readonly customInput = input(false);
readonly customBinding = hostBinding('attr.custom', () => this.customInput());
} For other solutions, this also sounds good
|
@alxhub just wondering - is no-decorator signal-way approach even considered or you just haven't touched it yet? I'm about the way @c-harding provided: constructor() {
hostBinding('class.hidden', () => this.isHidden());
hostBinding('class.hidden', this.isHidden); // alternative: isHidden is a signal
} I'm curious about potential disadvantages of such approach if you already discussed it. For me it would make a great fit with |
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
I am currentely trying to use new
input signal api
but I am unable to replace this code with DRY.Proposed solution
Maybe it should be replaced by something like
Alternatives considered
I was trying to find some solutions, but this is not working
The text was updated successfully, but these errors were encountered: