Issue
How can I append the variable to the href link ? I tried something like -
$scope.downloadFile=(fileName,id)=>{
<a href='https://downloadFile?fileName='+fileName+'&id='+encodeURIComponent(id)></a>;
}
This is not working.
Solution
Using template literals will help make it more readable, but put the backticks on the outside of the whole string. Additionally, when you use arrow functions you can omit the return statement, but only if you avoid using curly braces. Your function wasn't returning anything
$scope.downloadFile = (fileName,id) => `<a href="https://downloadFile?fileName=${fileName}&id=${encodeURIComponent(id)}"></a>`;
Here's a sample in plain JS
const downloadFile = (fileName,id) => `<a href="https://downloadFile?fileName=${fileName}&id=${encodeURIComponent(id)}"></a>`
console.log(downloadFile("THEFILE","THEID"));
Answered By - Kinglish
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.