Here am printing uploaded photo in console.log on button click.
Is it possible to print any dummy photo when user is not uploaded the pic??
var app = angular.module('myApp', []) app.controller('myController', function($scope) { $scope.saveDetails = function(doc) { console.log(doc.file) }; }) app.directive("fileread", [function () { return { scope: { fileread: "=" }, link: function (scope, element, attributes) { element.bind("change", function (changeEvent) { var reader = new FileReader(); reader.onload = function (loadEvent) { scope.$apply(function () { scope.fileread = loadEvent.target.result; }); } reader.readAsDataURL(changeEvent.target.files[0]); }); } } }]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myApp" ng-controller="myController" ng-init="init()"> <div>upload profile photo</div> <input type="file" id="file1" name="file" fileread="doc.file"/> <button ng-click="saveDetails(doc)">save</button> </div>
inside $scope.saveDetails function check for doc. if undefined, assign a default value.
$scope.saveDetails = function(doc) {
if(doc === undefined) {
// assign a dummy photo.
}
console.log(doc.file)
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.