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

Issue with nested directives and scopes, bindings get detached #1831

Closed
shock01 opened this issue Jan 18, 2013 · 2 comments
Closed

Issue with nested directives and scopes, bindings get detached #1831

shock01 opened this issue Jan 18, 2013 · 2 comments

Comments

@shock01
Copy link

shock01 commented Jan 18, 2013

When creating a parent and a child directive which are both transclude binding will occur just fine.

However after calling scope.$apply within the child directive the bindings on the child directive get detached from the Controller

I am fairly new to angular and don't know if this is a duplicate/already reported issue

Thnx

Example:
http://jsfiddle.net/29cS6/2/

@pkozlowski-opensource
Copy link
Member

@shock01 this is scoping issue. As explained here: http://docs.angularjs.org/guide/directive transclusion creates a child scope. In your case click handler was updating a value in a child scope while the parent was untouched. So no binding was "detached".

The make it work you need to bind to an object's property instead of directly binding to scope's property. This works OK: http://jsfiddle.net/L97bq/. Please note that this is recommended "best practice": http://www.youtube.com/watch?v=ZhfUv0spHCY&feature=g-user-u

@shock01
Copy link
Author

shock01 commented Jan 19, 2013

Thanks for clarifying
Stef
Op 19 jan. 2013 12:56 schreef "Pawel Kozlowski" [email protected]
het volgende:

@shock01 https://github.com/shock01 this is scoping issue. As explained
here: http://docs.angularjs.org/guide/directive transclusion creates a
child scope. In your case click handler was updating a value in a child
scope while the parent was untouched. So no binding was "detached".

The make it work you need to bind to an object's property instead of
directly binding to scope's property. This works OK:
http://jsfiddle.net/L97bq/. Please note that this is recommended "best
practice": http://www.youtube.com/watch?v=ZhfUv0spHCY&feature=g-user-u


Reply to this email directly or view it on GitHubhttps://github.com//issues/1831#issuecomment-12453930.

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

No branches or pull requests

2 participants