각도 앱에서 HTML 콘텐츠를 수신하면 HTML 문서에 삽입하지만 가져올 수 없습니다. 예 minimized code on plunker 및 javascript
에서 나는 다음 컨트롤러가 : 변수 trustedHtml에 html로 저장
class ReadCtrl
constructor: (@$scope, @$rootScope, @$compile, @$sce, @$window, @webService) ->
@getData()
getData: ->
promise = @webService.getBookText()
promise.then @success, @error
success: (response) =>
@$scope.html = response.data
@$scope.trustedHtml = @$sce.trustAsHtml(@$scope.html)
console.log $('.book_contents').first().children()
ReadCtrl.$inject = ["$scope", "$rootScope", "$compile", '$sce', "$window", "webService"]
angular.module("bookReader").controller "ReadCtrl", ReadCtrl
방법 성공을 한 다음 뷰에 바인딩 :
<div class="br_container">
<div class="br_source_container" ng-bind-html="trustedHtml">
</div>
</div>
내용을 보여줍니다하지만,이 console.log $('.book_contents').first().children()
이있다 제로 요소. 내가 @$rootScope.$digest()
같은 것을 삽입 할 때 오류가 발생합니다 :
Error: [$rootScope:inprog] $digest already in progress
그로 컴파일 방법으로 인해 =>
: 나는 또 다른 오류가 =>
->
에 변경한다면
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
this.success = __bind(this.success, this);
:
TypeError: Cannot read property '$scope' of undefined
success
의 첫 번째 줄에는 기능이 없습니다. 따라서 this
은 success
함수에서 정의되지 않았습니다. 아마도 promise로 호출 되었기 때문입니다.
$('.br_source_container').html(@$compile(@$scope.trustedHtml)(scope))
의 또 다른 방법은 동일한 오류가 발생합니다.
그래서 삽입 된 부분의 DOM HTML을 가져와야합니다.
은 컨트롤러 내부을 console.log()를 실행할 수 없습니다 wors 방법이에 대한 존중
timeout
으로 해결하고 완료 될 때까지 사이클을 소화 기대합니다. – charlietfl문제를 복제하는 데모를 만들지 마십시오. 이 단순화 된 버전 인 http://plnkr.co/edit/V8WJqR?p=preview도 작동하지 않습니다. – zishe
나는 커피를 잘 사용하지 않는다 ... throw 오류는 bookReader 모듈을 초기화 할 수 없다 ... 구문 문제이거나 somehting이어야한다 – charlietfl