Making a switch statement on my partials angularjs -
i'm having problem, i'm unable ng-switch work on partials. i'm trying upload image before upload must first check if included image size doesn't reach 25kb.
here controller code:
$scope.validateavatar = function(files) { var fd = new formdata(); $scope.filesize = files[0].size; $scope.filemaxsize = 25; //take first selected file fd.append("file", files[0]); $scope.uploadavatar = function() { api.uploadavatar($scope.main.user.email, fd) .then(function(result) { console.log(result.data); }, function(result) { console.log(result); }) }; };
and partials code:
<form data-ng-submit="uploadavatar()"> <input type="file" name="file" onchange="angular.element(this).scope().validateavatar(this.files)"/> <div ng-switch on="filesize / 1024 < filemaxsize"> <div ng-switch-when="true"> <input type="submit" value="upload avatar"> </div> <div ng-switch-default> please choose avatar. </div> </div> </form>
also think validation enough when checking image file size, if image included size:20mb, validation still catch it? sorry in first place haven't been able make work switch statements first . :(
you need call $scope.$apply()
after changed $scope.filesize
manually.
btw, why not let $scope.filemaxsize = 25 * 1024;
Comments
Post a Comment