1. Add Plugins
1.1 Installing Ngcordova
1.2 Install select Picture Plugin
1.3 Installing the Upload plugin
1.4 Viewing the installation plug-in collection
2.html Code
<Divclass= "Item Item-icon-right"> <span>Cover picture</span> <Iclass= "icon Ion-images Royal"data-tap-disabled= "true"Ng-click= "Taskfmpicker ()"></I> </Div> <Divclass= "Item Item-body" > <imgclass= "Full-image"ng-src= "{{fmimage}}" /> </Div> <Divclass= "Item Item-icon-right"> <span>Picture albums</span> <Iclass= "icon Ion-images Royal"data-tap-disabled= "true"Ng-click= "Taskxcpicker ()"></I> </Div> <Divclass= "Row Row-wrap item-calm" > <Divclass= "Col col-50"ng-repeat= "(k,v) in Images"><imgng-src= "{{V.imgurl}}"style= "width:120px;height:120px; "/> <P><Buttontype= "button"class= "button Button-small button-outline button-positive"Ng-click= "Delimgs (v.imgurl)">Delete</Button></P></Div> <Div> </Div> </Div>
3.controller Code
//Cover Selection$scope. taskfmpicker=function () { varOptions ={maximumimagescount:1, Width:600, Height:600, Quality:80 }; $cordovaImagePicker. Getpictures (Options). Then (function(results) {varURI = Results[0], name=URI; if(Name.indexof ('/'))) { vari = name.lastindexof ('/')); Name= name.substring (i + 1); } $scope. Fmimage=URI; $scope. Uploadimage (URI,0); }, function(Error) {alert (error); }); } //Select album$scope. taskxcpicker=function () { varOptions ={maximumimagescount:5, Width:600, Height:600, Quality:80 }; $cordovaImagePicker. Getpictures (Options). Then (function(results) { for(vari = 0; i < results.length; i++) { //console.log (' Image URI: ' + results[i]);$scope. Images.push ({"Imgurl": results[i],id:0}); $scope. Uploadimage (Results[i],1) ; } }, function(Error) {//Error getting photos }); } //Upload Image$scope. Uploadimage =function(uri,type) {varFileURL =URI; varOptions =Newfileuploadoptions (); Options.filekey= "File"; Options.filename= Fileurl.substr (Fileurl.lastindexof ('/') + 1); Options.mimetype= "Image/jpeg"; varServer=encodeuri (ENV. apiurl+ "/upload/imgupload"); varFT =NewFiletransfer (); $ionicLoading. Show ({Template:' Upload ... ' }); Ft.upload (FileURL, Server,function(data) {//Alert (json.stringify (data)); varRESP =Json.parse (Data.response); if(resp[0].status==1){ if(type==0) {$scope. Fmimgelist.push (resp[0].filename); //alert ($scope. Fmimgelist.join (', ')); } Else{$scope. Xcimgelist.push ("0" + "|" +resp[0].filename); }} $ionicLoading. Hide (); }, function(Error) {//Alert (json.stringify (Error));$ionicLoading. Hide (); }, Options); }
Ionic Select image Upload