2

I have working with one angularjs example i have face one problem is that i have load html view then after one div is content html data that is come from controler(database call) also data content html tag like <hr> <images> but that are display as it is not render html so i want to render that html part to.

I know my problem is delayed data come from data base so that will dispay as a plan text.

I use ng-bind-html till they are display pain text not render html tags.

I have one answer is late page loading that will succesfully work but that is not the proper way bcoz some time database data may take long time that is not working in this type of condition.

2
  • Please be clear about your need and your english, very confusing. better put it in points Commented Mar 19, 2014 at 5:36
  • @RaviMone in controler i call one database and database query return the html content that content put in view. Commented Mar 19, 2014 at 5:39

2 Answers 2

3

Hi jay you have to make directive for your example which is name bind-unsafe-html pass your html string or content in that and then it will re render your html content. For Example.

app.directive('bindUnsafeHtml', ['$compile', function ($compile) {
  return function(scope, element, attrs) {
        console.log("in directive");
      scope.$watch(
        function(scope) {
          // watch the 'bindUnsafeHtml' expression for changes
          return scope.$eval(attrs.bindUnsafeHtml);
        },
        function(value) {
          // when the 'bindUnsafeHtml' expression changes
          // assign it into the current DOM
          element.html(value);

          // compile the new DOM and link it to the current
          // scope.
          // NOTE: we only compile .childNodes so that
          // we don't get into infinite loop compiling ourselves
          $compile(element.contents())(scope);
        }
    );
};
}]);
Sign up to request clarification or add additional context in comments.

Comments

0

I can understand your problem it's a problem of asynchronous jscript call.

http://www.w3schools.com/tags/att_script_async.asp

you can not expect the script embedded in your HTML code to work properly. You need to separate it from your HTML and make it async.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.