aalimovs aalimovs - 3 months ago 16
AngularJS Question

Accessing parent scope in isolated directive

I'm building click to edit directives, but have issues understanding how to access parent scope in an isolated directive.

Example: http://jsfiddle.net/ADukg/3591/

scope: {},


It works if I "unisolate" the scope removing scope: {}; but need the isolated scope.

UPDATE:

Done it adding

controller: 'FormCtrl',


To the directive. See http://jsfiddle.net/ADukg/3601/

Answer

You could use the $parent property on the isolate scope to get direct access to the parent scope, but normally you'll want to use attributes to specify which parent scope properties the directive needs to do its work.

If you need to change the parent scope properties in the directive, bind with = (two-way objects). If you only need the string values of the parent scope properties in the directive, bind with @ (one-way strings).