Comments (4)
A computed would certainly work.
I think pipes are a somewhat easier way of reusing data transformation logic in templates than having to expose a computed signal inside the components.
Let's imagine that the date pipe uses a globally configured signal holding the timezone or the locale, or the preferred pattern. I prefer having to import DatePipe and be able to use {{ someObject().someDate | date }}
, than having to add
formattedDate = computed(() => formatDate(someObject().someDate));
to the component.
This is even truer if the pipe is used repeatedly inside a for loop for example.
If Angular was designed from scratch around signals now, my guess is that pipes would not exist. But since they do, I think they should work in the most intuitive way, and be consistent with the rest of the framework, where a signal change causes the template to be refreshed.
TBH, I don't have a real specific use-case here. This issue came out in a question in the Angular Discord, where someone else asked whether updating a signal would cause the pipe to be reexecuted.
from angular.
While we could make this change, there is a broader question about pure pipes usefulness with signals. Our thinking was that most of the pure pipe usages would be replaced by computed
. Would this work for your case? If not, could you share more about your particular scenario?
from angular.
Well, I guess what you'd really like to do is something like this: signal() | mappingFunction
and all you have to do is provide a source signal and a pure function. The computed
part is done for you.
from angular.
While we could make this change, there is a broader question about pure pipes usefulness with signals. Our thinking was that most of the pure pipe usages would be replaced by
computed
. Would this work for your case? If not, could you share more about your particular scenario?
I think this is a wrong assumption. I use a lot of pipes that have additional parameters within an ngFor. Something like this:
<ng-container *ngFor="let item of list()">
<div>{{ otherSignal() | somePipe : item }}</div>
</ng-container>
I'm not sure how to create computes with different parameters or compute factories or something like this? I think pipes are still a very useful and helpful way to isolate certain logic and not have it repeatedly inserted into multiple components computed properties.
I also just came across this issues while we had a very strange behavior with signals.
When putting a new object into a signal with spread operators everything worked fine. But as we wanted to optimize we added an equal function to the signal which then lead to strange behaviors on signals with pipes as the pipes were only triggered once.
from angular.
Related Issues (20)
- API abort error occurs specifically when rendering the page in Mozilla Firefox HOT 1
- The inherited component cannot be fully destroyed. HOT 2
- TypeError: Cannot set property 'nodeValue' of undefined HOT 1
- registerOnValidatorChange not called when bind in template form on the form element
- numberAttribute transform is not working when passing null HOT 3
- Support for Opening URLs in New Tab with State in Angular Router HOT 2
- UrlMatcher no longer receives the full url SegmentGroup after redirect HOT 2
- Improve misleading error message for control flow when HTML close tags are missing
- toSignal's runtime error message does not get tree shaken away in prod build
- Suggested fixes for first-app/14-http Step 3 Sample JSON HOT 1
- ErrorHandler stop working on Angular 18?
- Problem adding firebase HOT 1
- new Lifecycle hook ngOnServer HOT 1
- Support configuration of attachShadow when Custom Elements are created
- Deprecate "waitForAsync" in @angular/core/testing
- Use WebGL for testing in continuous integration HOT 1
- JIT compiler unavailable error with blank screen ( after updated from Angular 15.1.0 -> 16.2.14) HOT 10
- [Bug]: Cannot read properties of undefined (reading 'each') of zone-testing
- ng-content Projection with e-columns Directives Not Working with our own Angular grid component HOT 3
- Allow to pass a custom cookie parser function to create XSRF_COOKIE_NAME
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.