0

に渡されたものに基づいて異なるHTMLでディレクティブは、私はその後、私のディレクティブはサービスを呼び出し、それがcontent角度リターン

にデータを返します。この

<lcd-code lcdcode="{{data.code}}"></lcd-code> 

のように見えますhtmlコード内のディレクティブを持っています

// the top part of the directive 
    template: '<div ng-bind-html-unsafe="content"></div>', //'<div>blah</div>', 
     link: function (scope, element, attrs) { 
      var res = ""; 
      var promise = customerService.getKey(attrs.lcdcode) 
       .then(function (result) { 
        res = result; 
        scope.content = result; 

        console.log('scope.content', scope.content); 
       }) 
       .catch(function() { 
        console.log('problem'); 
       }); 

     } 
     //bottom part of directive ... 

何data.codeがあると私は渡しています0または1など。

だから私は本当にカスタム送り返されるHTMLを構築されて何をしたいのか...

は、それがその後、私はそれが1が、私はどのようにすることができます

アウトバック
<div> 
     <div> this is not ok</div> 
    </div> 

を送信したい場合はアウトバック

<div>ok now</div> 

を送りたい

に渡さ0あると言います私はこれを達成する?

答えて

0

説明したようにユースケースは簡単ですか?次にng-switchを使用できます。 lcdcodeとすぐcustomerService.getKeyとして戻り、あなたのHTMLを設定し、あなたのモジュールの後ろにコントローラがこのようになります

場所:

+0

を注入... –

0

NG-バインド-HTML-安全ではないが廃止されました read here

ngBindHtml を含める必要があります

と私は、HTMLの多くを提供ディレクティブを持って終了したいルートモジュールでngSanitize

angular.module('app', ['ngSanitize'])

.directive('lcdCode', function() { 

    return { 
     scope: { 
     lcdcode: '<' 
     }, 
     template: '<div ng-bind-html="content"></div>', 
     link: function(scope, element, attrs) { 
     var value = 1; 
     scope.content = "ok now"; 
     if (scope.lcdcode == 1) { 
      scope.content = "this is not ok"; 

     } 

     } 
    } 
    }) 

の作業Plunker