I am building a file uploader in Angular4. I need to create a custom object of a file, which has some fields and methods inside, every time a user is dropping/selecting a file.
class File {
public isSent: boolean: false;
public send() {
//a http call here
}
constructor(
private http: Http
)
}
The problem is that in component, services are created as singletons so there would be only one instance of file per component. I need multiple instances created dynamically.
I can do something like:
let file = new File();
however DI doesn't seem to work here properly as I need to use Http module inside the file instance.
how to manage such situation?
What I basically need is a simple Class implementation that is using some Angular features (Http) basing on which I would create objects.
Then, in view, I could just bind file.send()
to a button.
Just to clarify that it's not a duplicate: I don't want to inject multiple instances by DI in constructor. I want to create it dynamically on user action.