Allow constants, enums, functions to be used in templates without having to add component members
## I'm submitting a... <!-- Check one of the following options with "x" --> <pre><code> [ ] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report <!-- Please search GitHub for a similar issue or PR before submitting --> [ ] 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: </code></pre> ## Current behavior Templates cannot refer to anything not directly associated with the component, so you can't for example do this: ```html <div *ngIf="user.id === someConstant"> </div> <div *ngIf="user.status === UserStatus.Active"> <!-- UserStatus is an enum --> </div> <div *ngIf="isDevMode()"> </div> ``` To make this work, I have to declare these as members of my component: ```typescript import { someConstant } from './somewhere'; import { UserStatus } from './somewhere'; import { isDevMode } from '@angular/core'; export class MyComponent { public someConstant = someConstant; public UserStatus = UserStatus; public isDevMode = isDevMode; } ``` These can quickly clutter the component code, and can't be used for const enums. For const enums I have to duplicate the entire enum into a constant, which becomes a maintenance headache. ## Expected behavior It would be helpful if I could use constants, enums and functions directly from within t
Posted by pcroc on Sep 14, 2018, 9:27 AM
Tags
Related issues
- Add 65536 size support for maps
- TypeScript 7.1 Iteration Plan
- nvim-treeconfig: upstream nvim-treesitter
- Add the "action" and "method" attributes to <button>
- [FEATURE] Support multiple Connector accounts (same connector, different accounts) in Claude and Claude Code on the web (claude.ai/code)
- > We were imposed GitHub for so many exercises!
Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments
support (Software)
Add 65536 size support for maps
TypeScript 7.1 Iteration Plan
nvim-treeconfig: upstream nvim-treesitter
Add the "action" and "method" attributes to <button>
[FEATURE] Support multiple Connector accounts (same connector, different accounts) in Claude and Claude Code on the web (claude.ai/code)
> We were imposed GitHub for so many exercises!
Add support for Visual Studio 2026 Integration
Support for Helm v4
Allow constants, enums, functions to be used in templates without having to add component members
## I'm submitting a... <!-- Check one of the following options with "x" --> <pre><code> [ ] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report <!-- Please search GitHub for a similar issue or PR before submitting --> [ ] 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: </code></pre> ## Current behavior Templates cannot refer to anything not directly associated with the component, so you can't for example do this: ```html <div *ngIf="user.id === someConstant"> </div> <div *ngIf="user.status === UserStatus.Active"> <!-- UserStatus is an enum --> </div> <div *ngIf="isDevMode()"> </div> ``` To make this work, I have to declare these as members of my component: ```typescript import { someConstant } from './somewhere'; import { UserStatus } from './somewhere'; import { isDevMode } from '@angular/core'; export class MyComponent { public someConstant = someConstant; public UserStatus = UserStatus; public isDevMode = isDevMode; } ``` These can quickly clutter the component code, and can't be used for const enums. For const enums I have to duplicate the entire enum into a constant, which becomes a maintenance headache. ## Expected behavior It would be helpful if I could use constants, enums and functions directly from within t
Comments (0)
No comments yet. Start the discussion.