How to get the field "$parent" from a dynamic?

43 views
Skip to first unread message

Freewind

unread,
Jan 22, 2013, 7:48:16 AM1/22/13
to haxe...@googlegroups.com
Hi, all:

I'm using haxe with angularjs, sometimes I need to get the "$parent" field from a "scope" object, which is declared as "Dynamic".

Since "$" is not allowed in a field name, I can't use:

    scope.$parent

What's the correct way?

tecteun

unread,
Jan 22, 2013, 7:58:38 AM1/22/13
to haxe...@googlegroups.com
just a guess: did you try 
scope['$parent'] 
or 
untyped scope['$parent']
?

Op dinsdag 22 januari 2013 13:48:16 UTC+1 schreef Freewind het volgende:

Freewind

unread,
Jan 22, 2013, 8:04:31 AM1/22/13
to haxe...@googlegroups.com
    scope['$parent']

is invalid, with the error message: String should be Int

    untyped scope["$parent"]

Is find, but I wonder if it's possible not to use "untyped"

tecteun

unread,
Jan 22, 2013, 8:34:05 AM1/22/13
to haxe...@googlegroups.com
Reflect.field(scope, "$parent") maybe?

Freewind

unread,
Jan 22, 2013, 8:54:46 AM1/22/13
to haxe...@googlegroups.com
Yes, it works, or:

using Reflect;
scope.field("$parent");

On Tuesday, January 22, 2013 9:34:05 PM UTC+8, tecteun wrote:
Reflect.field(scope, "$parent") maybe?

Juraj Kirchheim

unread,
Jan 22, 2013, 10:33:50 AM1/22/13
to haxe...@googlegroups.com
Be careful with `using Reflect;` though. The compiler sometimes mistakenly assumes that `field` is an actual method of `scope`.


Freewind

unread,
Jan 22, 2013, 10:23:08 PM1/22/13
to haxe...@googlegroups.com
Thanks to know it
Reply all
Reply to author
Forward
0 new messages