Skip to content

Commit ac987f6

Browse files
committed
initial commit
0 parents  commit ac987f6

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

.jshintrc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"node": true,
3+
"browser": true,
4+
"esnext": true,
5+
"bitwise": true,
6+
"camelcase": true,
7+
"curly": false,
8+
"eqeqeq": true,
9+
"eqnull": true,
10+
"immed": true,
11+
"indent": 2,
12+
"latedef": true,
13+
"newcap": true,
14+
"noarg": true,
15+
"quotmark": "single",
16+
"regexp": true,
17+
"undef": true,
18+
"unused": true,
19+
"strict": true,
20+
"trailing": true,
21+
"smarttabs": true,
22+
"globals": {
23+
"angular": false,
24+
"_": true
25+
}
26+
}

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright © 2014 Jose Luis Rivas
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
angular-file-model
2+
==================
3+
4+
Simple Angular.js directive that allows input element's of type `file` to be
5+
handled in models inside a controller's scope.
6+
7+
Usage
8+
-----
9+
10+
Install with bower:
11+
12+
bower install angular-file-model --save
13+
14+
Add to your HTML files:
15+
16+
<script src='/bower_components/angular-file-model/angular-file-model.js'></script>
17+
18+
Now, inject to your application:
19+
20+
angular.module('myApp', ['angular-file-model']);
21+
22+
Ready to use in your controllers!:
23+
24+
`file.html`:
25+
26+
<input type='file' file-upload='fileModel'>
27+
<button type='button' ng-click='upload()'>Upload</button>
28+
29+
`controller.js:`
30+
31+
var DemoCtrl = [
32+
'$scope',
33+
function ($scope) {
34+
$scope.upload = function () {
35+
$scope.fileModel // This is where the file is linked to.
36+
};
37+
}
38+
]
39+
40+
Author
41+
------
42+
© 2014, Jose Luis Rivas `<[email protected]>`.
43+
44+
License
45+
-------
46+
The files are licensed under the MIT terms.

angular-file-model.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// angular-file-model
3+
// ==================
4+
//
5+
// Directive that makes the inputs with type `file` to be
6+
// available in the `$scope` and be assigned to a model.
7+
//
8+
(function () {
9+
'use strict';
10+
11+
angular.module('angular-file-model')
12+
.directive('fileModel', [
13+
'$parse',
14+
function ($parse) {
15+
return {
16+
restrict: 'A',
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+
});
26+
}
27+
};
28+
}]);
29+
30+
})();

bower.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "angular-file-model",
3+
"version": "0.0.1",
4+
"authors": [
5+
"Jose Luis Rivas <[email protected]>"
6+
],
7+
"description": "Angular support for file in models",
8+
"main": "index.js",
9+
"keywords": [
10+
"file",
11+
"model",
12+
"angular",
13+
"directory"
14+
],
15+
"license": "MIT",
16+
"ignore": [
17+
"**/.*",
18+
"node_modules",
19+
"bower_components",
20+
"test",
21+
"tests"
22+
]
23+
}

0 commit comments

Comments
 (0)