i'm using a AngularJS custom directive to implement html file input.I used an open source library which is on Github.But when i'm trying to access the scope value from the controller, it's showing as undefined variable.
Following is the directive code,
angularApp.directive('file', function() {
return {
restrict: 'AE',
scope: {
file: '@'
},
link: function(scope, el, attrs){
el.bind('change', function(event){
var files = event.target.files;
var file = files[0];
// scope.file = file;
scope.file = file;
scope.$parent.file = file;
scope.$apply();
});
}
};
});
Following is the html code
<input type="file" class="form-control" name="file" required>
But here in the html code other html snippets have ng-models which is binding to a scope object.As an example,
And this uses a ng-submit attribute with addNewUser(resources.newUser)
Following is part of controller code
$scope.addNewUser = function(data) {
console.log('FILE PATH IS :' + $scope.file);
}