Skip to content

Instantly share code, notes, and snippets.

@jpcercal
Created February 5, 2016 19:40
Show Gist options
  • Select an option

  • Save jpcercal/0f37bdc3a9ed3e67eb41 to your computer and use it in GitHub Desktop.

Select an option

Save jpcercal/0f37bdc3a9ed3e67eb41 to your computer and use it in GitHub Desktop.
How to Fix the problem with the AngularJS + MDL thats not fire the event input when data is loaded using a external resource with $http ou $resource
(function() {
var yourModuleName = angular.module("modules.yourModuleName");
yourModuleName.directive('ngModel', function() {
return {
restrict: 'A',
priority: -1,
link: function(scope, element, attr) {
// Hack to fire the change event when the model
// receives an update of value form an api by example..
// Warning: Not remove this directive when using the Material Design Lite
scope.$watch(attr.ngModel, function(value) {
if (attr.type === 'text' || attr.type === 'number' || attr.type === 'email') {
// https://github.com/cekurte/javascript-event-dispatcher
var dispatcher = new EventDispatcher(element[0]);
dispatcher
.dispatch('change')
.dispatch('input')
;
}
});
}
};
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment