Sha256: 6937c8c6e2c617f8c19a52e248a6274aa9fa425cb2d5e3eded68cabe5a2f308d
Contents?: true
Size: 1.1 KB
Versions: 10
Compression:
Stored size: 1.1 KB
Contents
module = angular.module('maestrano.components.file-model',[]) # Allows angular binding on <input type="file"> # Usage: <input type="file" file-model="someScopeObject.file"> module.directive("fileModel", [ '$parse', '$compile', ($parse, $compile) -> return { restrict: 'A', link: (scope, element, attrs) -> model = $parse(attrs.fileModel) modelSetter = model.assign element.bind('change', -> scope.$apply( -> modelSetter(scope, element[0].files[0]) ) ) # The filelist on an <input type="file"> is read only # which means we cannot clear the list of files attached to it # -- # The watcher below detects when the file-model is set to null, # undefined or '' and automatically replaces the input element # by a new one (no filelist attached) scope.$watch(model , (value, oldValue)-> if !angular.equals(value,oldValue) && (!value? || value = '') clone = $compile(element.clone())(scope) element.replaceWith(clone) ) } ])
Version data entries
10 entries across 10 versions & 1 rubygems