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
Allow for the ngSrc (and other inputs to change) when using NgOptimizedDirective #47813
Comments
The same thing would be required if used in cdk virtual scroll |
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list. You can find more details about the feature request process in our documentation. |
Hey @kbrilla please upvote the issue if it's something you feel would be good for the framework. |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
watching |
I don't think this directive is very useful without being dynamic, as requested here |
One of the example use cases is to use it for a component which listens to the This will currently result in error and needs to be fixed by double navigation (eg |
We also encountered this issue and had a workaround to rerender it using: https://www.npmjs.com/package/ngx-rerender |
Also encountered this issue, particularly in trying to make ngSrcset dynamic. The lack of ngSrc/ngSrcSet being non-bindable makes it difficult to use in a more advance application. Looking forward to this as a future feature, as otherwise ngOptimizedImage looks great. |
I would also love this feature. At the moment i have to change the most |
Any update? |
Quick update: the change that allows I'm closing this ticket for now, please create a new ticket if changing other inputs is blocking you from using |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Which @angular/* package(s) are relevant/related to the feature request?
common
Description
Currently an error is thrown (in dev mode) when one of the inputs changes on an
img
when when usingNgOptimizedImage
(the directive)The directive currently only supports the most basic case of rendered once and only once, but there are many use cases where an image may change (realtime applications for example). Our use case in particular is a website builder that allows the user to edit the page inline (and eventually in realtime). Heres some screenshots from Trellis.org to demonstrate this:
A user can click to change the media which opens up a photo library using Unsplash and then crops the image, after the server response the
ngSrc
is updated with the new image (currently no other inputs change as the element is a static size)Currently did does not work as inputs are not allowed to change.
Our rendered live pages (the ones the users of our users end up seeing after the page is finished being built) use the directive already but it would be nice if our website builder itself could be using it as well.
Proposed solution
Allow for the Inputs to change and check and update either all of the attributes or only the ones that would be affected by that specific attribute(s).
In
ngOnChanges
instead of throwing an error (we may still want to throw an error for some, likepriority
) determine what attributes on theimg
tag changed and need to be updated (or just update them all by callingsetHostAttributes()
again.Alternatives considered
Existing solutions to this are a little hacky and annoying to do but are as such:
https://angular-team.slack.com/archives/C08M4JKNH/p1666193540352369?thread_ts=1666128103.036069&cid=C08M4JKNH
<ng-template>
and create an embedded view (as per @AndrewKushnir):https://angular-team.slack.com/archives/C08M4JKNH/p1666132985022759?thread_ts=1666128103.036069&cid=C08M4JKNH
You may try wrapping an <img> into <ng-template> in this case and create a view dynamically (via ViewContainerRef.createEmbeddedView) - this would re-create the view containing an <img> and you can control when this view should be re-created.
The text was updated successfully, but these errors were encountered: