angular: Methods in templates don't understand Infinity value
I’m submitting a…
Bug report
<button (click)="setMax(Infinity)"></button>
Current behavior
setMax
gets undefined
Expected behavior
setMax
has to get Infinity
Minimal reproduction of the problem with instructions
http://plnkr.co/edit/GisrghRD3HQkn0wcRdR7?p=preview
Environment
Angular version: 4.4.4
Browser: any
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (12 by maintainers)
@Methods … you can’t use a global thing for a direct template binding, only through a class’s property.
Template "variable"s are properties of context object, it’s the nature of semantic for not having access to JavaScript
[[global]]
properties. Instead, properties on__proto__
are always accessible, so there’s a common case for usingconstructor
template “variable” to access static properties like{{ constructor.name }}
.I’m opposing to a semantic-level exception in the template language just because something is a bit more common. Adding support for
To observe the the existence ofundefined
could just be a design mistake in the very first version. A significant evidence is that AngularJS does not supportundefined
in template.undefined
, a string concatenation like{{ undefined + '' }}
can be used.@tytskyi In Angular template
undefined
is treated specially like a keyword/literal (by lexer), changing the context value won’t affect it. Similar tocontext.true = false
won’t change the meaning oftrue
in template.The problem is why
undefined
got special treatment while other globals (Infinity
,NaN
) aren’t.