Add an option in the @Component() decorator to add scope to the view template
See original GitHub issueWhich @angular/* package(s) are relevant/releated to the feature request?
common
Description
To expose constants or enums to a template is messy and becomes uncomfortable to manage.
It would be great if there was another way to bind data without adding it to the class.
Proposed solution
Add an option to the @Component() decorator to quickly bind data without polluting the class.
It could look like this:
import { myBigData, MY_CONSTANT } from './data';
enum Colours {
Red,
Green,
Blue,
}
@Component({
selector: 'app-colours',
templateUrl: './colours.html',
scope: [Colours, myBigData, MY_CONSTANT],
})
class ColoursComponent {}
These would be available in the template.
<button (click)="trigger(Colours.red)"></button>
<div *ngFor="let item of myBigData">{{ item }}</div>
{{ MY_CONSTANT }}
Alternatives considered
An alternative could be a second decorator potentially, however that doesn’t sound great. A different name could work too of course.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:19
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Component - Angular
Decorator that marks a class as an Angular component and provides configuration metadata that determines how the component should be processed, instantiated ...
Read more >Angular @ViewChild: In-Depth Explanation (All Features ...
The @ViewChild decorator cannot see across component boundaries! Visibility scope of @ViewChild template queries. This means that queries done ...
Read more >Understanding the ViewChild and ViewChildren decorators in ...
A view query is a requested reference to a child element within a component view which contains metadata of the element. The scope...
Read more >Templates, Styles & View Encapsulation • Angular - codecraft.tv
We've covered the basics of the @Component decorator in the quickstart. We explained how decorators work and both the template and selector configuration ......
Read more >A deep dive on Angular decorators - Ultimate Courses
With decorators, we can simply put the @Input() decorator above the ... selector: 'example-component', template: '<div>Woo a component!
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
Thanks for linking the duplicates @rafaelss95; closing as dup of #25963.
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.