I am not sure if I am phrasing all of this correctly; a lot has changed in Angular2. I am trying to pass form data to a component's service. I want to pass this data whenever the "Generate" button is clicked. I am encapsulating the form data in an object, and want to pass that object to a service that's injected into the component. The service performs all of the heavy lifting. All the component really does is display the output.
generator.component.ts
export class Generator {
passwords: string[]; // output array
passwordsObj: Object = { // form data passed to service
letters: "",
numbers: "",
symbols: "",
amount: ""
};
constructor(gs: GeneratorService) {
this.passwords = gs.generatePasswords(passwordsObj); // originally hard-coded, I want to now trigger this method when the "Generate" button is clicked
}
clicked(obj) {
// handle the click event?
}
}
I want the generatePasswords
method to take the passwordsObj
as an argument. I know how to do that. I just don't know how to trigger the service's generatePasswords
method when the component's button is clicked.
generator.component.html snippet
<button type="submit" (click)="clicked(passwordsObj)">Generate</button>