Skip to content

Commit 8b66ceb

Browse files
committed
Revert "easier to understand"
This reverts commit f024fca.
1 parent f024fca commit 8b66ceb

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

angular-file-model.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,23 @@
88
(function () {
99
'use strict';
1010

11-
angular.module('angular-file-model', [])
12-
11+
angular.module('angular-file-model')
1312
.directive('fileModel', [
14-
function () {
15-
return {
13+
'$parse',
14+
function ($parse) {
15+
return {
1616
restrict: 'A',
17-
scope: {
18-
fileModel: '='
19-
},
20-
link: function(scope, element) {
21-
element.bind('change', function(event){
22-
var files = event.target.files;
23-
var file = files[0];
24-
25-
scope.fileModel = file ? file.name : undefined;
26-
27-
scope.$apply();
28-
});
17+
link: function(scope, element, attrs) {
18+
var model = $parse(attrs.fileModel);
19+
var modelSetter = model.assign;
20+
21+
element.bind('change', function(){
22+
scope.$apply(function(){
23+
modelSetter(scope, element[0].files[0]);
24+
});
25+
});
2926
}
30-
};
31-
}
32-
]
33-
);
27+
};
28+
}]);
3429

3530
})();

0 commit comments

Comments
 (0)