지시문을 통해 일부 내용을 추가하려고 시도하지만 절대로 표시되지 않습니다. 컴파일 된 범위를 기록하면 Object가 표시됩니다.데이터를 추가하지 않는 각도 지시문
angular.module('blancAppApp')
.controller('SlugCtrl', function ($scope, WpApi, $compile, $filter, ngProgressLite) {
// the Content to be rendered.
$scope.maincontent = [];
// load remote data from the server.
function loadRemoteData() {
// The WpApiService returns a promise.
WpApi.getContents()
.then(
function(post) {
applyRemoteData(post);
});
}
// apply the remote data to the local scope.
function applyRemoteData(newContents) {
$scope.maincontent = $compile(newContents[0].content)($scope);
console.log($scope.maincontent); // Object getting logged
}
}).directive('maincontent', function() {
return {
restrict: 'A',
scope: {
maincontent: '=maincontent'
},
link: function (scope, element, attrs) {
element.append(scope.maincontent );
}
};
});
마크 업 당신은 요청이 비동기이기 때문에 범위에 감시자를 등록해야
<div id="main-content" data-maincontent="maincontent"></div>
,하지만 복사본을 만듭니다. 그리고 그것은 서버에서 아직 반환하지 않은 지시문을 전달할 때 추측됩니다. 시도하고 console.log scope.maincontent 귀하의 지시문 링크 함수 및 호출 전에 참조하십시오 "applyRemoteData"- 기능 – Gustav
맞아요'당신은 바로'console.log (scope.maincontent)''링크 : function () {}'가 먼저 호출되어'[]'이 비어있다. – fefe