0

I have a html

<div id="doc1"></div>

after that I add add new html inside id "doc1"

document.getElementById("doc1").innerHTML = '<div id="doc2">{{ value }}</div>';

accurately there should be

<div id="doc1"><div id="doc2">{{ value }}</div></div>

but {{ value }} not working to bind

this my JS code

(function () {
    angular
    .module('myApp')
    .controller('MyController', myController);

    function myController($scope){
      Initial();
    
      function Initial(){
         document.getElementById("doc1").innerHTML = "<div id="doc2">{{ value }}</div>";
         $scope.value = "Hi There";
      }
    }
}) ();

3
  • 1
    document.getElementById() and .innerHTML have nothing to do in an Angular app. It is out of "Angular's world". Selecting elements by ID and adding text to them is not how Angular works. Commented Mar 2, 2021 at 8:55
  • stackoverflow.com/questions/40788937/… Commented Mar 2, 2021 at 10:31
  • I see, thankyou for your answer Nitheesh Commented Mar 3, 2021 at 3:08

1 Answer 1

0

Try to use ngBindHtml docs

in template

<div id="doc1" ng-bind-html="htmlData"></div>

in controller

$scope.htmlData = "<div id="doc2">{{ value }}</div>";
$scope.value = "Hi There";
Sign up to request clarification or add additional context in comments.

1 Comment

I do follower you answer but result still same, {{ value }} not bind

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.