ngValue ignored in ng-content and ng-template
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[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
[ ] Other... Please describe:
This issue was previously reported at https://github.com/angular/angular/issues/22374, which was closed as a support request even though I don’t believe it was intended to be one.
Current behavior
ngValue
is ignored if (1) the <option>
s are provided via <ng-content>
to a component (even if the component simply wraps a vanilla <select>
) or (2) if the <option>
s are in an <ng-template>
.
Expected behavior
ngValue
should work the same in these cases as it does when using a plain <select>
with directly nested <option>
s.
Minimal reproduction of the problem with instructions
Please see https://codesandbox.io/s/2z2n2v0pjp .
Here is a screenshot of the reproduction:
What is the motivation / use case for changing the behavior?
Many applications require a custom-styled <select>
component that allow the caller of the component to provide their own <option>
s.
Environment
Angular version: 6
Browser:
- [x] All
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:7 (5 by maintainers)
Top Results From Across the Web
ngValue is ignored when used inside ng-content in Angular
I have created a custom control say my-select-input in Angular that wraps native select input. Template looks like this.
Read more >Everything you need to know about ng-template, ng-content ...
Angular wraps the host element (to which the directive is applied) inside <ng-template> and consumes the <ng-template> in the finished DOM by ...
Read more >ngRepeat - AngularJS: API
The ngRepeat directive instantiates a template once per item from a collection. Each template instance gets its own scope, where the given loop...
Read more >Angular 10 - Avoid using ::ng-deep (ngdeep)
CSS Query Selectors within a View's component style, are being ignored by Angular anytime we attempt to change a "deep" style. With Angular, ......
Read more >Difference between ng-template, ng-container and ng-content
As the name suggests the is a template element that Angular uses with structural directives ( *ngIf , *ngFor , [ngSwitch] and custom ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ngValue
relies on DI ofSelectControlValueAccessor
.Both failing examples the repro have the templated options defined outside any injector with
SelectControlValueAccessor
.There is one case that will work, however. If
SelectWrappedComponent
providesSelectControlValueAccessor
and the options are defined in its content, then it works.I.e. This gives you the ability to write a decorated/custom select component with content-projected options that work well with ngModel/ngValue.
https://codesandbox.io/s/jrjnlvxl5
We looked at this again today. This is generally related to the lack of a robust composability model in Forms. Solving that general issue would also solve this one. The work is on the horizon, after we’re through the upcoming focus on reactivity.