0
votes

Is there a way to import additional variables/data from the dialog-service to the controller?

For example I have an array of possible options in a form of my app-view. I fetch the data via an API from a server.

I'd like to edit an entry with an aurelia-dialog and don't want to fetch the data again to avoid unnecessary traffic in my app.

How can i pass the array additionally to the model. Pack it all together in an Object and unwrap it in the controller? As far as I know the activate-method of the controller only takes one argument, doesn't it?

Thank you

1

1 Answers

2
votes

Isn't the example in the repository exactly what you are looking for? The person attribute is passed to the dialog service via the settings object (model: this.person). This may be data you fetched from the server. As you mentioned, you can of course add multiple objects to the model as well which will be available in the activate() method of your dialogs vm.

import {EditPerson} from './edit-person';
import {DialogService} from 'aurelia-dialog';
export class Welcome {
  static inject = [DialogService];
  constructor(dialogService) {
    this.dialogService = dialogService;
  }
  person = { firstName: 'Wade', middleName: 'Owen', lastName: 'Watts' };
  submit(){
    this.dialogService.open({ viewModel: EditPerson, model: this.person}).then(response => {
      if (!response.wasCancelled) {
        console.log('good - ', response.output);
      } else {
        console.log('bad');
      }
      console.log(response.output);
    });
  }
}