3
我試圖使用angularJs資源從服務器下載文件,但它不工作。 我的代碼如下:使用angularJs資源下載XML文件
// service
angular.module("someModule")
.factory('generate', ['$resource', '$rootScope', function ($resource, $rootScope) {
return $resource('some url...');}]);
//Js controller file - I'm getting the 'generate' service in the head of the controller
$scope.$on('generateFile', function(){
generate.get();
});
//html
<a ng-click="$emit('generateFile')"></a>
當我鍵入URL它下載的文件 - 所以服務器端的罰款。但是,我找不到使用角度資源下載文件的任何示例。 感謝您的幫助
你能張貼文件的內容作爲一個例子?對$ resource使用JSON非常簡單,但使用XML似乎並不那麼容易。您可能會更好地使用$ http,並手動解析數據。 – martinczerwi
[在客戶端使用angular從nodejs下載文件]的可能重複(http://stackoverflow.com/questions/24652927/downloading-files-from-nodejs-using-angular-at-client-side) –