0

일부 html을 컴파일하도록 지시문을 작성한 다음이를 요소에 바인딩합니다. 여기

이 지침

export class BindCompileHtmlDirective implements ng.IDirective { 

     restrict = 'A'; 



     link = (scope: ng.IScope, element: any, attrs: any, ctrl: any) => { 
     scope.$watch((scope) => { 
      console.log(attrs); 
      //Also tried attrs.BindCompileHtmlDirective which returns undefined 
      //Tried attrs.$attr.bindCompileHtml also which returns 0 too 
      return scope.$eval(attrs.bindCompileHtml); 
     }, (value) => { 
      console.log(value); 
      // In case value is a TrustedValueHolderType, sometimes it 
      // needs to be explicitly called into a string in order to 
      // get the HTML string. 
      element.html(value && value.toString()); 

      var $phe = this.$compile(element.contents())(scope); 
      //element.after($phe); 
     }); 
     } 

     constructor(private $compile: any) { 
     } 



     static factory(): ng.IDirectiveFactory { 
     const directive = ($compile: any) => new BindCompileHtmlDirective($compile); 
     directive.$inject = ['$compile']; 
     return directive; 
     } 

    } 

    angular.module('rundeckManager.directives') 
     .directive('bindCompileHtml', BindCompileHtmlDirective.factory()); 

이며, 여기에 구현 :

<span id="id-of-span" bind-compile-html="{{TabsDomains.domainsLabelHtml}}"></span> 

attrs에 객체가 좋아 보인다 내가 컴파일 할 필요가 문자열의 값을 포함, 여기에 ATTR 객체입니다 :

attrsObjectLog

하지만 내 직접 필자는 컴파일 된 문자열 대신 값으로 0을 반환하고 이유를 이해하지 못합니다.

누군가가 설명하고 도움을 줄 수 있다면 정말 도움이 될 것입니다. 어쩌면, "$의 평가는 각 표현입니다하지 HTML : attrs.bindCompileHtml

내가 여기에 코멘트에 대한 답을 붙여있어

을 반환 :

+0

과 같이 DOM에 배치 할 준비가되었습니다. 나는 틀릴 수도 있지만 '$ eval'은 HTML이 아닌 각도 표현을위한 것인가, 아마도이 HTML이 0으로 평가되는 각도 표현식일까요? 'bindCompileHtml' 내용은 그대로 DOM에 배치 될 준비가되었습니다. 예를 들어'ng-click '에있는 것을 실행하고 싶다면, 이것은'$ eval'을 가질 것입니다 (전체 HTML이 아닌 ng-click의 내용을 추출한 후) – Kaddath

+0

정말 옳았습니다! 이것은 잘 됐네요! 나는 그 질문에 대한 답으로 그것을 게시 할 것이다! –

+0

도와 주셔서 감사합니다. – Kaddath

답변

0

같이,이 경우에만 필요 질문의 의견에 말했다 각도 표현으로이 HTML은 0으로 평가됩니까? bindCompileHtml 내용은 "012 attrs.bindCompileHtml; '로 시도한 것처럼"