Angularjs - 如何添加angularjs文件上传到meanjs库 [英] Angularjs - how to add angularjs-file-upload to meanjs library

查看:260
本文介绍了Angularjs - 如何添加angularjs文件上传到meanjs库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想实现的 danialfarid的 angularjs文件上传使用的 meanjs 。但它不是的工作

Am trying to implement danialfarid's angularjs-file-upload using meanjs. But it's not working.

是否有可能与meanjs使用它?

Is it possible to use it with meanjs??

推荐答案

您应该能够使用它,它看起来像你错过,包括angularjs文件上传模块项目的一个步骤,所以这里的步骤包括这个模块或应用MeanJS任何外部角模块:

You should be able to use it, it looks like you miss a step in including the angularjs-file-upload module into your project, so here's the steps for including this module or any external angular module in MeanJS Application:

1通过凉亭与命令安装angularjs文件上传文件上传后:

1- after installing angularjs-file-upload file upload via bower with the command:

bower install ng-file-upload --save

2 - 你应该添加引用angularjs-文件upload.js文件,在应用程序页面布局,这在文件中完成:配置\\ ENV \\ all.js的,你应该有这样的行:

assets: {
        lib: {
            css: [
                'public/lib/bootstrap/dist/css/bootstrap.css',
                'public/lib/bootstrap/dist/css/bootstrap-theme.css'               
            ],
            js: [
                'public/lib/ng-file-upload/angular-file-upload-shim.min.js',
                'public/lib/angular/angular.js',
                'public/lib/ng-file-upload/angular-file-upload.min.js',

3,那么你应该包括angularjs文件上传为你的应用角度的依赖,这是文件中完成:公开\\ config.js ,在结尾处添加angularFileUpload在此行中数组:

3- then you should include angularjs-file-upload as a dependency in your angular application, this is done in the file: public\config.js, add 'angularFileUpload' at the end of the array in this line:

var applicationModuleVendorDependencies = ['ngResource', 'ngCookies',  'ngAnimate',  'ngTouch',  'ngSanitize',  'ui.router', 'ui.bootstrap', 'ui.utils', 'angularFileUpload'];

4-你应该能够使用文件上传在您看来,现在,如果不还完成下一步然后再试。

4- you should be able to use the file uploader in your view now, if not complete also the next step then try again.

5,如果你想在你的控制器使用angularjs文件上传服务,您应该注入上传服务( $上传)在你的模块registeration是这样的:

5- if you want to use the angularjs-file-upload service in you controller, you should inject the upload service ($upload) in your module registeration like this:

angular.module('myModuleName').controller('MyController', ['$scope', '$stateParams', '$location', 'Authentication', '$upload',
    function ($scope, $stateParams, $location, Authentication, $upload) {
// your controller code goes here
});

6,现在你应该苹果使用来自angularjs文件上传的$上传服务在你的角度控制器是这样的:

6- now you should be apple to use the $upload service from angularjs-file-upload in your angular controller like this:

 $upload.upload({
                url: '/serverRouteUrl', //upload.php script, node.js route, or servlet url
                method: 'POST', //Post or Put
                headers: {'Content-Type': 'multipart/form-data'},
                //withCredentials: true,
                data: JsonObject, //from data to send along with the file
                file: blob, // or list of files ($files) for html5 only
                //fileName: 'photo' // to modify the name of the file(s)                
            }).success(function (response, status) {
                   //success 
                }
            ).error(function (err) {
                   //error
                }
            );

这将是所有的客户端,不是说你必须配置您的服务器端应用程序或路由(县)能够处理与文件上传请求,使用库一样的 Multer 会做的伎俩。

That will be all from client side, not that you have to configure your server side app or route(s) to be able to handle requests with file uploads, using a library like Multer will do the trick.

这篇关于Angularjs - 如何添加angularjs文件上传到meanjs库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆