Created
December 15, 2014 09:02
-
-
Save endaaman/5cb7892a1a61a1d87ed9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
angular.module modulePage | |
.config ($stateProvider) -> | |
$stateProvider | |
.state 'upload', | |
url: '/upload' | |
templateUrl: '/page/upload/upload.html' | |
controller: 'UploadCtrl' | |
.controller 'UploadCtrl', | |
($scope, $http) -> | |
$scope.upload = -> | |
if not $scope.files | |
return | |
data = | |
hoge: 'fuga' | |
formData = new FormData() | |
formData.append 'file', $scope.files[0] | |
formData.append 'data', angular.toJson data | |
$http.post '/api/document', formData, | |
headers: | |
'Content-type': undefined | |
transformRequest: null | |
.success (res)-> | |
console.log res | |
.error (res)-> | |
console.log res | |
.directive 'files', -> | |
restrict : 'A' | |
scope: | |
files: '=' | |
link: (scope, element, attrs)-> | |
element.on 'change', (event)-> | |
scope.$apply -> | |
scope.files = event.target.files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment