I'm trying to add an option to add an image in my Angular 2 App and wanted to use Filestack (formerly filepicker.io) to store the images.
So I included these script tags in my index html file above </body>
, as Filestack suggested (and put my API key in) and added the <input>
field in my component html which displays the form to add a new recipe:
in index.html:
<script src="https://static.filestackapi.com/v3/filestack-0.5.0.js"></script>
<script>
var url = '';
var client = filestack.init('myApiKey');
function showPicker() {
client.pick({
maxFiles: 1
}).then(function(result) {
url = JSON.stringify(result.filesUploaded[0].url)
});
}
</script>
in recipe-form.component.html:
<input type="button" value="Upload" onclick="showPicker()" />
Now that works perfectly fine, it uploads the image and if I add console.log(url)
it also shows the url of the image. However, there seems to be no way to get that variable into the RecipeFormComponent where I want to add the url to the object I'm creating there. How could I do that?
I have found a lot of stuff about how to use Filestack with AngularJS, but not how to do this in Angular 2...
Is there anything you know of that could help me?