Created
July 23, 2015 17:36
-
-
Save bitflower/262b8f7309d64561c1a0 to your computer and use it in GitHub Desktop.
ngModelOnChange: bind ngModel if input[type=file] to scope
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() { | |
| 'use strict'; | |
| var app = angular.module('net.bitflower.ngModelOnChange', []); | |
| // Listens to the change event of the input and sets Angular's value / ngModel of the element | |
| app.directive('ngModelOnChange', function() { | |
| return { | |
| restrict: 'A', | |
| require: '?ngModel', | |
| link: function(scope, el, attrs, ngModel) { | |
| el.bind('change', function() { | |
| scope.$apply(function() { | |
| ngModel.$setViewValue(el.val()); | |
| }); | |
| }); | |
| } | |
| }; | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment