Created
February 5, 2016 19:40
-
-
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
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
| (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