Skip to content

tsaikd/angular-files-model

Repository files navigation

angular-files-model GitHub version

Dependency Status devDependency Status Build Status Built with Grunt

AngularJS directive that allows input element's of type file to be handled in models inside a controller's scope

fork from https://github.com/ghostbar/angular-file-model

Usage

Include angular-files-model.min.js in your application.

<script src="angular-files-model.min.js"></script>

Add the angular-files-model module to your application's dependencies.

angular.module("myApp", ["angular-files-model"]);

Ready to use in your controllers:

file.html:

<input type="file" ng-files-model="fileModel">
<button ng-click="upload()">Upload</button>

controller.js:

var DemoCtrl = [
	'$scope', 
	function ($scope) {
		$scope.upload = function () {
			$scope.fileModel // This is where the file is linked to.
		};
	}
];

Notes

If use in angular ui bootstrap modal, you need to handle the scope problem with a parent scope variable.

file.html:

<input type="file" ng-files-model="wrap.fileModel">
<button ng-click="upload()">Upload</button>

controller.js:

var DemoCtrl = [
	'$scope', 
	function ($scope) {
		$scope.wrap = {};
		$scope.upload = function () {
			$scope.wrap.fileModel // This is where the file is linked to.
		};
	}
];

If you use this module you can give it a thumbs up at http://ngmodules.org/modules/angular-files-model

About

AngularJS directive that allows input element's of type file to be handled in models inside a controller's scope

Resources

License

Stars

Watchers

Forks

Packages

No packages published