incuna / angular-bind-html-compile

Directive that calls $compile on trusted HTML, allowing directives in an API response.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Selective Compiling via another directive

RSchlenker opened this issue · comments

Hello,
at first I have to say that this directive really helped me during my project!
But at the moment I am trying to realize two bindings on the same page, the only problem I have with this is, that each time I change the content of one of them, both will compile and therefore a ng-repeat repeats a second time, which is not applicable for my case.

Is there any workaround for this scenario?
I could imagine a second directive with a boolean value where you can dynamically change if the binding has to be compiled or not.

Hi @Deleadon, I'm happy that the library was helpful. Could post a simple case code example to show what you are trying to acheive?

Okey,

This is my html I want to bind to the field.

<div ng-controller="testCtrl">
  <div ng-repeat="type in types">
      <p>type</p>
  </div>
</div>

On the top level:

<div bind-html-compile="htmlCode"></div>

I have a second one like this but without an ng-repeat.
But every time I compile the second one, this one will repeat itself, so I get a multiple of the original repeated div's

My controllers are something like this:

app.controller('testCtrl',['$scope', function($scope) {
  $scope.types = [1,2,3,4];
}])
app.controller('mainCtrl',['$scope',function ($scope){
   $http.get('/partials/testHTML').then(function (response) {
      $scope.htmlCode = response.data;
    });
}])

I thought about something like this:

<div bind-html-compile="htmlCode" compileOn="compileDiv"></div>
 app.controller('mainCtrl',['$scope',function ($scope){
   $scope.compileDiv = evaluateIfDivShouldBeCompiled();
   $http.get('/partials/testHTML').then(function (response) {
      $scope.htmlCode = response.data;
    });
}])

Where I can dynamically evaluate if the html should be compiled.
My Key idea behind this was, that i wanted to stop the annoying reloading from recompiling