lorenzofox3 / flexy-layout

61 stars 19 forks source link

How to get access to Flexy Layout controller's blocks array? #12

Closed muser83 closed 10 years ago

muser83 commented 10 years ago

Hello

I want to print with json the current structure of the Flexy layout from my app. How can get it done?

lorenzofox3 commented 10 years ago

Hello there is not straightforward as the blocks array is in a private closure

however you can change the code

var blocks=[];

by

var blocks=this.blocks=[];

so that the blocks are available on the controller ctrl.blocks

Laurent

muser83 commented 10 years ago

Ok I have added a method to expose blocks property in flexyLayout controller like this:

            this.getBlocks = function() {
                return blocks;
            };

But... How can I call getBlocks from my app controller or from another directive? I am a newbie in AngularJS... Sorry

I have tried this, but launches a flexylayout controller not found error:

    angular.module('controlRoom').directive('flexyLayoutDebugger', function() {
        return {
            restrict: 'A',
            require: '^flexyLayout',
            link: function(scope,element,attrs, flexyLayoutCtrl) {

                element.bind("mouseenter", function(){
                    console.log(flexyLayoutCtrl.getBlocks());
                });
            }
        }
    });
lorenzofox3 commented 10 years ago

require:'^anyController'

imply that your directive expect to find a parent ont the dom tree which has the anyController directive attached (refer to documentationhttp://docs.angularjs.org/guide/directive )

so ...

...

will works when

will throw Exception

Laurent

On Fri, Jan 17, 2014 at 9:26 AM, muser83 notifications@github.com wrote:

Ok I have added a method to expose blocks property in flexyLayout controller like this:

        this.getBlocks = function() {
            return blocks;
        };

But... How can I call getBlocks from my app controller or from another directive? I am a newbie in AngularJS... Sorry

I have tried this, but launches a flexylayout controller not found error:

angular.module('controlRoom').directive('flexyLayoutDebugger', function() {
    return {
        restrict: 'A',
        require: '^flexyLayout',
        link: function(scope,element,attrs, flexyLayoutCtrl) {

            element.bind("mouseenter", function(){
                console.log(flexyLayoutCtrl.getBlocks());
            });
        }
    }
});

— Reply to this email directly or view it on GitHubhttps://github.com/lorenzofox3/flexy-layout/issues/12#issuecomment-32587526 .

muser83 commented 10 years ago

Yes, that was it! Thank you!