mohsen1 / json-formatter

Angular directive for collapsible JSON in HTML
http://azimi.me/json-formatter/demo/demo.html
Other
372 stars 85 forks source link

Provide an example using data-binding #33

Closed broyeztony closed 8 years ago

broyeztony commented 9 years ago

Hi guys,

First of all, congrats for the good job on this library. However, the lib does not seem to work using dynamic content. Say, i have:

json-formatter open="1" json="{'id':'1842922560001','name':'Siege','adKeys':'null','shortDescription':'Siege','longDescription':'null','creationDate':'1347753427318','publishedDate':'1347753427318','lastModifiedDate':'1436333769645','linkURL':'null','linkText':'null','tags':[]}" /json-formatter

this works fine.

Now if i have (code is copy/pasted outside of the controller context for simplicity...):

scope.feedContent = "{'id':'1842922560001','name':'Siege','adKeys':'null','shortDescription':'Siege','longDescription':'null','creationDate':'1347753427318','publishedDate':'1347753427318','lastModifiedDate':'1436333769645','linkURL':'null','linkText':'null','tags':[]";
json-formatter open="1" json="{{ feedContent }}"/json-formatter

=> output a Parse error:

Error: [$parse:syntax] http://errors.angularjs.org/1.3.14/$parse/syntax?p0=%7B&p1=invalid%20key&p2=2&p3=%7B%7B%20feedContent%20%7D%7D&p4=%7B%20feedContent%20%7D%7D
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:6:417
    at ib.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:190:165)
    at ib.object (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:199:324)
    at ib.primary (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:189:223)
    at ib.unary (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:196:478)
    at ib.multiplicative (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:196:205)
    at ib.additive (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:196:63)
    at ib.relational (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:195:435)
    at ib.equality (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:195:291)

Thanks for your feedback,

Keep going with the good job,

Cheers, Tony

mohsen1 commented 9 years ago

Hi, I'm glad you are happy with this. You should not put {{ }} in json attribute value if you are referring to scope variable:

So basically

<json-formatter open="1" json="feedContent" > </json-formatter>
broyeztony commented 8 years ago

Oh yeah… silly me. That works perfectly. Thanks for the quick answer!

Tony

On 16 Sep 2015, at 20:32, Mohsen Azimi notifications@github.com wrote:

Hi, I'm glad you are happy with this. You should not put {{ }} in json attribute value if you are referring to scope variable:

So basically

— Reply to this email directly or view it on GitHub https://github.com/mohsen1/json-formatter/issues/33#issuecomment-140835172.

mohsen1 commented 8 years ago

👍