How to access directive parent scope

I am starting to learn AngularJS and while trying to use a custom directive.

I cant seem to get the child to read the parentScope, according to angular documentation children accesible methods should be defined inside the controller of the parent directive. It looks like the changes directives are being run, but I cant seem to access the parent scope (function not defined acording to chrome).

Thanks in advance for any help

plunker

Answers


That's because you are using an Isolated scope(which is good). This statement isolates the scope from its parent

    scope: {
        key:'@',
        title:'@'
    },

Just pass the parent controller to the child like this.

require: '?^parentDirective'
link: function(scope, element, attrs, parentCtrl) {
   scope.parentCtrl = parentCtrl;
}

And then in the parent controller modify your could like this:

var self = this;

self.addColumn = function(data){
    $scope.columns.push(data);
};

You do not have direct access to the parent scope.


Need Your Help

applescript to create multiple sequentially numbered folders with a specific prefix

applescript

I would like to create an applescript that will create multiple folders with the same root name but the numbers change? or at least a repeating folder creation script until the person has enough fo...