Created
February 6, 2018 11:02
-
-
Save lucasdu4rte/07e449b5440582f54f15468a67352b0a to your computer and use it in GitHub Desktop.
Change attrs directive on AngularJS
This file contains 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
"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