javascript - AngularJs json-formatter json 属性作为范围变量

标签 javascript json angularjs angularjs-directive

我正在尝试使用 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 值时,一切正常。

最佳答案

jsonjson-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/

相关文章:

java - 使用 JSON Parsing with volley 更新 ListView 的最佳方法

javascript - $scope 在 Angular js 中不起作用

javascript - AngularJS + Fullcalendar 发送错误TypeError : Cannot read property '__id' of undefined

javascript - 如何将 onclick 变量放入对话框函数中

javascript - 我怎样才能使这个过渡平滑而不是跳跃起来

asp.net - JSON+ld结构化数据的站长工具验证

javascript - Angular 页面刷新中发生了什么为什么我的登录用户无法识别

javascript - 更改后重新加载 DOM

javascript - onsubmit cakephp图标更改功能

c# - 使用 Json.NET 测试嵌套键?