MEAN Stack File uploads

后端 未结 4 1530
生来不讨喜
生来不讨喜 2021-01-30 15:08

I\'ve recently started programming with the MEAN Stack, and I\'m currently implementing some sort of social network. Been using the MEAN.io framework to do so. My main problem r

4条回答
  •  抹茶落季
    2021-01-30 15:26

    Recently a new package was added to the list of packages on mean.io. It's a beauty!

    Simply run:

    $ mean install mean-upload

    This installs the package into the node folder but you have access to the directives in your packages.

    http://mean.io/#!/packages/53ccd40e56eac633a3eee335

    On your form view, add something like this:

        

    • {{image.name}}

    And in your controller:

        $scope.uploadFileArticleCallback = function(file) {
          if (file.type.indexOf('image') !== -1){
              $scope.article.images.push({
                'size': file.size,
                'type': file.type,
                'name': file.name,
                'src': file.src
              });
          }
          else{
              $scope.article.files.push({
                'size': file.size,
                'type': file.type,
                'name': file.name,
                'src': file.src
              });
          }
        };
    
        $scope.deletePhoto = function(photo) {
            var index = $scope.article.images.indexOf(photo);
            $scope.article.images.splice(index, 1);
        }
    

    Enjoy!

提交回复
热议问题