我正在尝试使用带有一些ajax数据的prettyprint.问题是,当调用指令时,数据没有准备好,所以我得到未定义的变量输出.
普兰克:http://plnkr.co/edit/fdRi2nIvVzT3Rcy2YIlK?p=preview
var app = angular.module('plunker',[]); app.controller('MainCtrl',function($scope,$http) { $scope.result = $http.get('data.json').success(function(result){ return result.data.dom }) }); app.directive('prettyprint',function() { return { restrict: 'C',link: function postLink(scope,element,attrs) { element.html(prettyPrintOne(scope.result)) } }; });