Hi,
I have 2 tables in database
currently my requirement is that based upon EmployeeId i am going to save multiple fiels into documents table
this is my excepted code
Employee
Id Name
1 aaa
2 bbbb
Documents
DId DocName Id
1 c:/Upload/uploadfiels/mahesh.text 1
2 c:/Upload/uploadfiels/mahesh.text 1
3 c:/Upload/uploadfiels/mahesh.2text 1
4 c:/Upload/uploadfiels/resume.text 2
5 c:/Upload/uploadfiels/word.text 2
6 c:/Upload/uploadfiels/file.2text 2
This is my below code
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<script>document.write('<base href="' + document.location + '" />');</script>
<script data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('MainCtrl', function ($scope) {
$scope.employees = [{ Name: 'aa' }, {Name:'bb' }];
$scope.files = [];
});
$scope.Save = function () {
}
app.directive('ngFileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var model = $parse(attrs.ngFileModel);
var isMultiple = attrs.multiple;
var modelSetter = model.assign;
element.bind('change', function () {
var values = [];
angular.forEach(element[0].files, function (item) {
var value = {
// File Name
name: item.name,
//File Size
size: item.size,
//File URL to view
url: URL.createObjectURL(item),
// File Input Value
_file: item
};
values.push(value);
});
scope.$apply(function () {
if (isMultiple) {
modelSetter(scope, values);
} else {
modelSetter(scope, values[0]);
}
});
});
}
};
}]);
</script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>UploadFile</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in employees">
<td><input type="text" ng-model="employee.Name" /></td>
<td><input type="file" ng-file-model="files" multiple /></td>
</tr>
</tbody>
</table>
<button ng-click="Save()">Save</button>
</body>
</html>