我正在尝试使用 json-formatter 在其中一个 View 中呈现 json .
在 Controller 中,我正在使用通过 REST API 请求架构的服务。当请求完成时,结果被分配给范围变量。代码片段如下:
.controller('SchemaCtrl', ['$scope', '$routeParams', 'Schema','$log', function($scope, $routeParams, Schema,$log){
Schema.show($routeParams.name).then(function(schema){
$scope.schema = schema;
$scope.schemaShow = true;
});
在 View 中我有下一个代码:
{{schema}}
<div>
<json-formatter open="1" json="{{schema}}"></json-formatter>
</div>
不幸的是,运行示例后我收到下一个错误:
Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{schema}}] starting at [{schema}}].
{{schema}}
我知道问题是由 json-formatter 引起的。在用正确的值进行 Angular 替换 {{schema}}
之前解释指令。我该如何使用json-formatter为了通过作用域变量传递值?
顺便说一句。 当我使用硬编码的 json 值时,一切正常。
最佳答案
json
是 json-formatter
中的 2 路绑定(bind),因此这里不需要插值标记 {{}}
<div>
<json-formatter open="1" json="schema"></json-formatter>
</div>
关于javascript - AngularJs json-formatter json 属性作为范围变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28107624/