Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Feature request: Ability to set value type for scope values imported from attributes #9279

Open
stsvilik opened this issue Sep 25, 2014 · 3 comments

Comments

@stsvilik
Copy link

In my Directives I would love to be able to specify that value coming from an attribute is of type boolean or number or perhaps even Date. Ideally I see it as an enhancement to your syntax where when you set scope hash you can also specify the type. For example:

scope: {
  myNumber: '#@', //Where # would attempt to cast value to Number
  myBoolean: '!@', //Where ! would attempt to cast value to Boolean
}

Rational for this is that very often I end up doing something like $scope.myValue === 'true' instead of just testing for its intended type.

@Narretz
Copy link
Contributor

Narretz commented Sep 25, 2014

Interesting. Somehow related, I often have boilerplate in observers that need to cast stuff to boolean. Wiht scope bindings I find it less useful, or better: I find it out of scope fo angular to include a type system.

@shahata
Copy link
Contributor

shahata commented Sep 25, 2014

For two way binding ('=') there is no need to cast since the scope variable will always be with the same type as the bound variable. This is only relevant for interpolated ('@') scope variables, which are always of string type. Or am I missing something?

@stsvilik
Copy link
Author

You're right I made a mistake, it should have been for one-way bound values '@' not '='. Apologies!
It is in fact to tackle values that always come as strings.

Corrected example.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants