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 comment:

  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



Follow this blog by Email

Popular Posts