In my component, I have imported a constant and I'm using it as is.
import { NullGuid } from "src/app/models/constants";
...
@Component({ ... })
export class TheComponent implements OnInit {
constructor(private service: SomeService) { this.proxy = NullGuid; }
...
proxy: string = NullGuid;
}
In the template, I can reach the service like this.
<div>{{this.service.getStuff()}}</div>
However, I can't do the same with the constant unless it's declared as shown above. Can I somehow expose the imported constant without declaring a proxy property for it?
I have a workaround for that with using pipes. I have a pipe something like below:
And use it like this :
EDIT: As @KonradViltersen mentioned in the comments i was thinking to use
value
instead ofargs
. But then an idea came with theAngular Language Service
. If you changeargs
type fromstring
to typekey
Language service will provide you auto completion which is good when you have large amount of constants. But if you changevalue
s type tokey
you will only have some error in your template that will tell you about type mismatch and no runtime errors. It becomes a preference how you use it.Also problem you are having stands with enums too.
Which can be used like
It will provide autocomplete for
Hard
but not forComplexity
Stackblitz