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)

Most upvoted comments

@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 using constructor 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 undefined could just be a design mistake in the very first version. A significant evidence is that AngularJS does not support undefined in template.

To observe the the existence of 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 to context.true = false won’t change the meaning of true in template.

The problem is why undefined got special treatment while other globals (Infinity, NaN) aren’t.