AngularJS supports .html(), .text() jQuery functionality. Here in below examples we can see how to set text or html to an element.

Steps to set text to an elemnt :

  1. Get angular element of html element
  2. Use .text() method to set text to that angular element
var myEl = angular.element( document.querySelector( '#divID' ) );
myEl.text('This is text. Here html tags will be displayed like normal tags. Example : <span style="font-weight:bold;"> Styled Text</span>');     

Set Text using ng-bind

ng-bind is for binding text to HTML element
<html ng-app="" ng-controller="myCtrl">
.....
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
.....
<input ng-model="divText"/>
.....
<div style="border:1px solid #ccc;padding:10px;" ng-bind="divText"></div>
<script>
function myCtrl($scope) {
  $scope.divText = 'some text';
}
</script>
Try It Your Self

Steps to set html to an element :

  1. Get angular element
  2. Use .html() method to set html to that angular element
var myEl = angular.element( document.querySelector( '#divID' ) );
myEl.html('This is html. Here html tags will be mixed with page. Example : <span style="font-weight:bold;"> Styled Text</span>');     

Set HTML using ng-bind-html

ng-bind-html is for binding HTML to element
<html ng-app="myApp" ng-controller="myCtrl">
.....
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-sanitize.js"></script>
.....
Enter some text in below text field <br/>
<input ng-model="divHtmlVar"/><br/><br/>
<div style="border:1px solid #ccc;padding:10px;" ng-bind-html="divHtmlVar"></div>
<script>
var myApp = angular.module('myApp', ['ngSanitize'])
function myCtrl($scope) {
    $scope.divHtmlVar = '<b>main html</b>';
}
</script>
Try It Your Self

32 comments:

  1. Good Example to Set Text or Html to div using AngularJS, i am interesting to learn AngularJs 4, give me more examples

    ReplyDelete
  2. The great service in this blog and the nice technology is visible in this blog. I am really very happy for the nice approach is visible in this blog and thank you very much for using the nice technology in this blog
    Angularjs course in chennai

    ReplyDelete
  3. Hi, great to see your website. I like the content and the research done behind every aspect of your blog. It looks great and very knowledgeable. Keep it up the good work. PCNSE questions answers

    ReplyDelete
  4. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.

    rpa training in bangalore | best rpa training in bangalore | rpa course in bangalore | rpa training institute in bangalore | rpa training in bangalore | rpa online training | rpa training in Chennai

    ReplyDelete
  5. Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
    python course in pune
    python course in chennai
    python Training in Bangalore

    ReplyDelete
  6. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
    Best Devops Training in pune
    Data science training in pune | Data Science training institute in Pune

    ReplyDelete
  7. When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.
    Amazon Web Services Training in Pune | Best AWS Training in Pune
    AWS Online Training | Online AWS Certification Course - Gangboard
    Top 110 AWS Interview Question and Answers | Advanced AWS interview Questions and Answers – AWS jobs

    ReplyDelete
  8. Nice post. Thanks for sharing! I want people to know just how good this information. It’s interesting content and Great work.
    Thanks & Regards,
    VRIT Professionals,
    No.1 Leading Web Designing Training Institute In Chennai.
    And also Those who looking for
    HTML courses training institutes in Chennai
    CSS courses training institutes in Chennai
    Bootstrap courses training institutes in Chennai


    ReplyDelete
  9. There are different definitions of product development depending on the services companies offer and how they market themselves. Check out this article to learn more about the product development companies.

    ReplyDelete




  10. And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
    software Testing Training |Best Software Training Institute in Chennai



    ReplyDelete
  11. www.excelr.com/digital-marketing-training
    digital marketing training
    I finally found great post here.I will get back here. I just added your blog to my bookmark sites. providing.

    ReplyDelete
  12. www.excelr.com/digital-marketing-training-in-hyderabad - digital maketing course in hyderabad
    I finally found great post here.I will get back here. I just added your blog to my bookmark sites. providing.

    ReplyDelete
  13. Nice blog, good post, informative and helpful post and you are obviously very knowledgeable in this field. Very useful and solid content. Thanks for sharing


    Data Science Courses in Bangalore

    ReplyDelete
  14. This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this..
    date analytics certification training courses
    data science courses training
    data analytics certification courses in Bangalore
    ExcelR Data science courses in Bangalore

    ReplyDelete
  15. Super site! I am Loving it!! Will return once more, Im taking your food additionally, Thanks.
    Data Science Course in Pune

    ReplyDelete

  16. This is really good blog information thanks for sharing .I am really impressed with your writing abilities

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสล็อตออนไลน์ >>> goldenslot
    สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย

    ReplyDelete
  17. I am really impressed with your post thank you for information


    เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีหวยให้คุณได้เล่น สมัครหวยออนไลน์ ได้เลย
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688
    ร่วมลงทุนสมัครเอเย่นคาสิโนกับทีมงานของเราได้เลย

    ReplyDelete
  18. Attend The Python Training in Bangalore From ExcelR. Practical Python Training in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python Training in Bangalore.

    ReplyDelete

  19. I am a new user of this site so here i saw multiple articles and posts posted by this site,I curious more interest in some of them hope you will give more information on this topics in your next articles.

    Data Science Course

    ReplyDelete
  20. This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again.
    machine learning course malaysia

    ReplyDelete
  21. I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more.
    data science course in singapore

    ReplyDelete

  22. It has fully emerged to crown Singapore's southern shores and undoubtedly placed her on the global map of residential landmarks. I still scored the more points than I ever have in a season for GS. I think you would be hard pressed to find somebody with the same consistency I have had over the years so I am happy with that.
    Thanks for sharing, live it.

    ReplyDelete
  23. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article.
    Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me.
    It should be noted that whilst ordering papers for sale at paper writing service, you can get unkind attitude. In case you feel that the bureau is trying to cheat you, don't buy term paper from it.
    Data Science Courses

    ReplyDelete
  24. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us

    You will get an introduction to the Python programming language and understand the importance of it. How to download and work with Python along with all the basics of Anaconda will be taught. You will also get a clear idea of downloading the various Python libraries and how to use them.
    Topics
    About ExcelR Solutions and Innodatatics
    Do's and Don’ts as a participant
    Introduction to Python
    Installation of Anaconda Python
    Difference between Python2 and Python3
    Python Environment
    Operators
    Identifiers
    Exception Handling (Error Handling)
    Excelr Solutions

    ReplyDelete
  25. Keep up the good work. Looking forward to view more from you.

    ReplyDelete

  26. Very interesting,good job and thanks for sharing such a good blog.your article is so convincing that I never stop myself to say something about it.You’re doing a great job.Keep it up.
    One data science
    One Machine Learning

    ReplyDelete

  27. Very interesting,good job and thanks for sharing such a good blog.your article is so convincing that I never stop myself to say something about it.You’re doing a great job.Keep it up.
    One data science
    One Machine Learning

    ReplyDelete
  28. You might comment on the order system of the blog. You should chat it's splendid. Your blog audit would swell up your visitors. I was very pleased to find this site.I wanted to thank you for this great read!!
    AI learning course malaysia

    ReplyDelete

Blogroll

Follow this blog by Email

Popular Posts