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
</div>

Angular Component Code

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

  document.addEventListener('DOMContentLoaded', function() {
    ng.platform.browser.bootstrap(app.AppComponent);
  });
})(window.app || (window.app = {}));

4 comments:

  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

    ReplyDelete
  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.

    ReplyDelete
  3. A systematic review aims to provide an in-depth prospectus of the applicable literature resources ( https://canvas.instructure.com/eportfolios/141659/Home/The_Relevance_of_University_Assignments ) on your research topic. Find relevant studies, papers, and publications in the field, broaden the knowledge on your subject, get useful insights.

    ReplyDelete
  4. I want to express my deep gratitude to this cool service, which helps students save their nerves and time for personal affairs https://writemyessaytoday.us/ 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.

    ReplyDelete

Blogroll

Popular Posts