I need one help.I need to add one random number with the file name using Angular.js.I am explaining my code below.
<div ng-class="{'myError': billdata.regdoc.$touched && billdata.regdoc.$invalid }">
<input type="file" class="filestyle form-control" data-size="lg" name="regdoc" id="regdoc" ng-model="regfile" ngf-pattern="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.wordprocessingml.document" accept="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.wordprocessingml.document" ngf-select="onRegFileSelect($file);" >
</div>
</div>
<div class="help-block" ng-messages="billdata.regdoc.$error" ng-if="billdata.regdoc.$touched">
<p ng-message="pattern" style="color:#F00;">This field only accepts .pdf,.ppt,.docx files.</p>
</div>
My controller file code is given below.
var regDocURL='';
$scope.onRegFileSelect=function(files){
console.log('docs details',files);
regDocURL=files;
}
var curnum=(Math.random() * new Date().getTime()).toString(36).replace(/\./g, '');
var regDocs=regDocURL;
var newRegPath=curnum+"_"+ regDocs.name;
regDocs.name=newRegPath;
console.log('reg file',newRegPath,regDocs);
Here in the console message i can not get the new file name which is including some random number.Here i need to include one random number(i.e-curnum
) with the file name.Please help me.