2

I am changing the class of a button, of a button group, using javascript within angular directive.

My update is happening correctly. But the change is not reflecting on screen until i click somewhere in the page.

angular.module('test', []).
directive('selected', function() {
  return {
    link: selectedLinker,
    restrict: 'A',
    replace: false
  }

  function selectedLinker(scope, element, attribute) {
    var groupname = attribute.selected;
    groupname = 'groupname';
    element.bind('click', function() {
      var elements = document.querySelectorAll('[selected=' + groupname + ']');
      for(var i=0; i<elements.length; i++) {
        var item = elements[i];
        item.classList.remove('selected');
      }
      this.classList.add('selected');
      //element.addClass('selected');
    })
  }
});

What am I missing here. I dont want to use jquery. Thanks.

Pluker Link

2
  • 1
    nothing to do with angular ... has to do with bootstrap :focus css selector. Inspect element in browser dev tools and look at css rules that apply ... will see the :focus selector as part of same rule for .selected Commented May 15, 2016 at 4:27
  • Thanks. I got it working. Commented May 15, 2016 at 4:43

2 Answers 2

1

try adding this to your css :

.btn:focus {
      background-color: inherit !important;
      color: inherit !important;
    }
Sign up to request clarification or add additional context in comments.

Comments

1

Add this.blur() after this.classList.add('selected'); in your directive's link function to clear the bootstrap CSS properties being applied due to the button being in focus.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.