Angular2 is providing [attr.<attribute name>] to bind attribute values. Here it is

Markup :

Observe below code, role attribute was bound to roleVal 
<div id="divID" [attr.role]="roleVal">
  This text color can be changed by class

Angular Component Code

Observe below functions addAttr, removeAttr, checkAttr
(function(app) {
  app.AppComponent = ng.core
      selector: 'my-app',
      templateUrl: 'attr1_template.html'
      constructor: function() {
        this.roleVal = '';
      addAttr:function() {
        this.roleVal = 'admin';
      removeAttr:function() {
        this.roleVal = '';
      checkAttr:function() {

  document.addEventListener('DOMContentLoaded', function() {
})( || ( = {}));


  1. I must say the blog post is just useful for everyone else reading it because the information and knowledge it contains is very important. I like the post! Excellent job! Keep sharing such valuable information through your blogs. Visit Custom essay writing service

  2. I just tried to set and remove attributes with Assignment Writing Services and Angular2, and the result was exactly as you said. Thank you very much for writing this amazing post here.

  3. A systematic review aims to provide an in-depth prospectus of the applicable literature resources ( ) on your research topic. Find relevant studies, papers, and publications in the field, broaden the knowledge on your subject, get useful insights.

  4. I want to express my deep gratitude to this cool service, which helps students save their nerves and time for personal affairs I have been cooperating with him for several years now, and I also ordered essays for my friend. Professionals in their field. Excellent authors. They write as for themselves. I am satisfied. I'm sure you will like it.



Popular Posts