Skip to content

Instantly share code, notes, and snippets.

@lucasdu4rte
Created February 6, 2018 11:02
Show Gist options
  • Save lucasdu4rte/07e449b5440582f54f15468a67352b0a to your computer and use it in GitHub Desktop.
Save lucasdu4rte/07e449b5440582f54f15468a67352b0a to your computer and use it in GitHub Desktop.
Change attrs directive on AngularJS
"use strict";
angular.module('app').directive('adaptativeDatetimePicker', function($http, $rootScope, $document, $window, $compile) {
return {
priority:1001, // compiles first
terminal:true, // prevent lower priority directives to compile after it
compile: function(el, attrs) {
if ($window.innerWidth <= 768) {
el.removeAttr('adaptative-datetime-picker'); // necessary to avoid infinite compile loop
el.removeAttr('data-smart-masked-input');
el.attr('type', 'datetime-local');
}else {
el.removeAttr('adaptative-datetime-picker'); // necessary to avoid infinite compile loop
el.attr('data-smart-masked-input', '99/99/9999 99:99');
}
var fn = $compile(el);
return function(scope){
fn(scope);
};
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment