8000 Async select field (new syntax) · Issue #18919 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

Async select field (new syntax) #18919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers an 10000 d 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

Closed
altschuler opened this issue Aug 29, 2017 · 7 comments
Closed

Async select field (new syntax) #18919

altschuler opened this issue Aug 29, 2017 · 7 comments
Labels
area: core Issues related to the framework runtime core: binding & interpolation Issue related to property/attribute binding or text interpolation cross-cutting: observables feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature
Milestone

Comments

@altschuler
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

It's currently not possible to easily select a property of an async object in a template without either

  1. Declaring it as a variable in an ngIf or using as
  2. Using the async pipe and existential operator, ie (thing$ | async)?.prop

Expected behavior / motivation

It would be very convenient with a new syntax to select properties directly off an observable. In the vein of typescript's existential operator, eg:

Instead of

<h1>{{ (hero$ | async)?.name }}</h1>
<p>{{ (hero$ | async)?.description }}</p>

// Alternatives exist, eg
<ng-template [ngIf]="hero$ | async" let-hero>
  <h1>{{ hero.name}}</h1>
  <p>{{ hero.description}}</p1
</ng-template>

It would be nice with

<h1>{{ hero$|.name }}</h1>
<p>{{ hero$|.description }}</p>

Meaning obj|.prop is practically syntax sugar for (obj | async)?.prop.

@Toxicable
Copy link

| already has a meaning in an Angular template, it's a pipe
Meaning that your proposed syntax already currently means something to Angular

That aside I don't like the syntax since it blurs the lines between normal objects and Observables where this should be distinct and not ambiguous

@altschuler
Copy link
Author

|. is currently invalid syntax, so it wouldn't conflict with existing syntax. ? also has a meaning, but ?. has another. The actual characters were just a suggestion, it could be something else.

I can see your point about it being ambiguous though, you're right it blurs the meaning of what the object is. Would it help if for non-observable objects the property would just be selected as a regular field (obj.prop)?

Another approach is simply using a pipe which is async and selects a field. Could be properly typed with typescripts keyof. This starts to feel more like something one should implement locally though, and looses the purpose of being short and concise. Eg. obj | select:'name'.

@kara kara added area: core Issues related to the framework runtime and removed area: forms labels Dec 5, 2017
@chuckjaz chuckjaz added the feature Issue that requests a new feature label Dec 5, 2017
@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2018
@pkozlowski-opensource pkozlowski-opensource added the core: binding & interpolation Issue related to property/attribute binding or text interpolation label Mar 13, 2020
@pkozlowski-opensource
Copy link
Member

This sounds very similar to the issue #15280 where there is a lot of discussion about pulling out certain property value from an observable. At the end of a day we might not implement the syntax proposed here but the use-case is real.

@angular-robot
Copy link
Contributor
angular-robot bot commented Jun 5, 2021

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.

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Jun 5, 2021
@angular-robot
Copy link
Contributor
angular-robot bot commented Jun 26, 2021

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added the feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors label Jun 26, 2021
@petebacondarwin
Copy link
Contributor

This is being tracked in the aggregate issue of #43485 for which we need to create a project proposal.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: binding & interpolation Issue related to property/attribute binding or text interpolation cross-cutting: observables feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

8 participants
0