File tree 1 file changed +15
-20
lines changed 1 file changed +15
-20
lines changed Original file line number Diff line number Diff line change 8
8
( function ( ) {
9
9
'use strict' ;
10
10
11
- angular . module ( 'angular-file-model' , [ ] )
12
-
11
+ angular . module ( 'angular-file-model' )
13
12
. directive ( 'fileModel' , [
14
- function ( ) {
15
- return {
13
+ '$parse' ,
14
+ function ( $parse ) {
15
+ return {
16
16
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
+ } ) ;
29
26
}
30
- } ;
31
- }
32
- ]
33
- ) ;
27
+ } ;
28
+ } ] ) ;
34
29
35
30
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments