Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to dynamically set open? #34

Open
ScottChapman opened this issue Sep 16, 2015 · 8 comments
Open

Any way to dynamically set open? #34

ScottChapman opened this issue Sep 16, 2015 · 8 comments

Comments

@ScottChapman
Copy link

I wanted to implement a mechanism where I would expand/collapse all the JSON Formatters with a button. But I couldn't get it to work.

Is there a way to do that?

@mohsen1
Copy link
Owner

mohsen1 commented Sep 16, 2015

No, but it's possible. We need to $watch open to update scope.isOpen when it changes. See here

A pull request is welcome. Make sure you write a test for it.

@raygig
Copy link

raygig commented Apr 19, 2017

Seems like an easy fix

Replacing https://github.com/mohsen1/json-formatter/blob/master/src/json-formatter.js#L154

with

scope.$watch('open', function(value) {
        scope.isOpen = !!scope.open;
}, false);

I have this working locally and it works well. For now I am copying the json-formatter package locally until this enhancement is merged.

@ric79
Copy link

ric79 commented Jun 1, 2017

Hello, any chance to fix the code as proposed? This will be really useful...

@mohsen1
Copy link
Owner

mohsen1 commented Jun 1, 2017

I'll merge and publish a small PR that only does that. #41 is way too much changes.

Please send a PR.

@ric79
Copy link

ric79 commented Jun 2, 2017

Now idea about PR. I'm just using your module :)
Sorry

@ric79
Copy link

ric79 commented Jun 14, 2017

Is it possible to fix it. It Will be rally usefull forum my progetto. Thank you!

@mohsen1
Copy link
Owner

mohsen1 commented Jun 14, 2017

@ric79 pull requests are welcome! :)

@nicolamontini
Copy link

@raygig I modified the library with your suggestion, but now how can i trigger the watcher? I tried to bind the open attribute of the directive and then changing the data model, but the watcher does not get triggered. I did something like this:

<json-formatter open="jsonDepth" json="jsonObj"></json-formatter>
<button ng-click="changeOpen()">CHANGE OPEN</button>

and in my controller:

$scope.jsonObj = my object;
$scope.jsonDepth = 10;
$scope.changeOpen = function() { $scope.jsonDepth = 1; };

The changeOpen function is triggered, but not the watcher. Can someone help? Many thanks in advance

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

No branches or pull requests

5 participants