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

The directive does not work on iOS cordova app

sarahsga opened this issue · comments

The $compile in the directive does not work on iOS cordova app, and prevents the HTML from getting rendered at all.

Thanks for reporting. Do you mind sharing some code? You're also welcome to submit a PR.

@wytrych
I solved it.

Here is the HTML that I wanted to bind to a scope variable:

facts.html

<div id="content" bind-html-compile="dynamicHTML" >

facts.controller.js

$http.get(url)
        .then(
        function(response){
          $scope.dynamicHTML = response.data;
        }

The content div, as a result, rendered nothing at all on Safari(web) and iOS (cordova)

The line in the bind-html-compile directive that was causing the rendering issue was Line 22 in angular-bind-html-compile.js
$compile(element.contents())(compileScope);
It prevented anything from rendering at all.

I wanted to enable click on just one anchor tag inside $scope.dynamicHTML. I replaced Line 22 above with the following code:
$compile(element.contents().find( "a" ))(compileScope);

That solved it.