Re: [angular.js] ng-click on directive with isolated scope

2,344 views
Skip to first unread message

Suller Andras

unread,
Jun 14, 2012, 4:22:59 AM6/14/12
to ang...@googlegroups.com
I'm not sure if there is a $parent when you use isolated scope:

" The 'isolate' scope differs from normal scope that it does not
prototypically inherit from the parent scope. This is useful when
creating reusable components, which should not accidentally read or
modify data in parent scope. "

If you want to access parent scopes in your directive, don't use isolated scope.

Andras

On Thu, Jun 14, 2012 at 11:26 AM, ItsLeeOwen <l...@coderebelbase.com> wrote:
> Shouldn't a widget/directive with ng-click="someFunction()" at least fire on
> it's parent scope without $parent?
>
> <my-widget ng-click"pleaseFireOnParentScope()"></my-widget>
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/kVb1A2MdinkJ.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.

jeffau...@ymail.com

unread,
Jun 14, 2012, 11:44:28 PM6/14/12
to ang...@googlegroups.com
I agree this feels really odd. I would expect at least some kind of event bubbling from ng-click, that could be captured from the parent scope. 

Nice to know about $parent - I didn't see it in the docs.



On Thursday, June 14, 2012 12:43:36 PM UTC-5, ItsLeeOwen wrote:
You can use $parent to get out of the isolated scope.  As much as I dislike the fact that passing evaluated/bound variables attributes to a directive results in an automatic isolated scope, it is what it is.  The angular team seems not to be interested in allowing a regular prototypically inherited parent scope.

Technically it might make sense that you'd have to specify $parent to get out of the isolated scope in ng-click, it just feels ugly.  I guess I'm back to my strong dislike of not being able to pass parameters to a widget via inline attributes without being stuck with an isolated scope.

Here's an example that working with $parent:  http://jsfiddle.net/ItsLeeOwen/AG3Dm/


Reply all
Reply to author
Forward
Message has been deleted
0 new messages