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.



Popular Posts