0

I'm trying to present json in one of the view using json-formatter.

In controller I am using service that is requesting schema via rest API. When request is completed result is assigned to the scope variable. Code snippet below:

.controller('SchemaCtrl', ['$scope', '$routeParams', 'Schema','$log',    function($scope, $routeParams, Schema,$log){
    Schema.show($routeParams.name).then(function(schema){
        $scope.schema = schema;
        $scope.schemaShow = true;
    });

In the view I have next code:

{{schema}}
<div>
    <json-formatter open="1" json="{{schema}}"></json-formatter>
</div>

Unfortunatelly after running example I am receiving next error:

Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{schema}}] starting at [{schema}}].
{{schema}}

I know that the problem is caused by json-formatter. Directive is interpreted before angular replace {{schema}} with proper value. How can I use json-formatter in order to pass values via scope variables?

Btw. When I use hardcoded json value everything is working well.

2
  • is schema a JSON object? or an interpreted JS object? i.e. is it a string or a js object? Have you console.log'ed the schema Commented Jan 23, 2015 at 10:20
  • schema is a JSON object but even if I am assigning JSON.stringify(schema) result is the same. In the console.log results seems to be ok. Commented Jan 23, 2015 at 10:46

1 Answer 1

1

json is 2-way binding in json-formatter, so no need interpolation mark {{}} here

<div>
    <json-formatter open="1" json="schema"></json-formatter>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.