5
일부 ajax 데이터와 함께 prettyprint를 사용하려고합니다. 문제는 지시어가 호출 될 때 데이터가 준비되지 않았기 때문에 정의되지 않은 변수 출력을 얻는다는 것입니다.AngularJs 지시어 비동기 데이터보기
Plunkr : 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))
}
};
});
나는 plunkr를 업데이트했지만, 문제가 해결되지 것 같다 ... – Tropicalista
@Tropicalista. 내 대답을 업데이트 해 봤어. – Cherniv