Created
          September 13, 2015 16:55 
        
      - 
      
- 
        Save devm33/fb82461d3fcc8d2aba74 to your computer and use it in GitHub Desktop. 
    angular directive to add/remove attributes like ngClass
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | angular.module('dynAttrs', []) | |
| .directive('dynAttrs', () => { | |
| return { | |
| link: function(scope, element, attrs) { | |
| scope.$watch(attrs.dynAttrs, (dynAttrs) => { | |
| _.each(dynAttrs, (val, attr) => { | |
| if(val) { | |
| element.attr(attr, val); | |
| } else { | |
| element.removeAttr(attr); | |
| } | |
| }); | |
| }); | |
| } | |
| }; | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment