Skip to content

Instantly share code, notes, and snippets.

@plwalters
Last active December 13, 2016 03:49
Show Gist options
  • Save plwalters/6928d1242621c7b6b6e5f6cab89e4710 to your computer and use it in GitHub Desktop.
Save plwalters/6928d1242621c7b6b6e5f6cab89e4710 to your computer and use it in GitHub Desktop.
DI inheritance
<template>
<require from="./sample"></require>
<h1>Dialog Repro</h1>
<sample></sample>
</template>
import {DialogService} from 'aurelia-dialog';
import {Prompt} from './prompt';
export class App {
person = { name: 'Test' };
static inject = [DialogService];
constructor(dialogService) {
this.dialogService = dialogService;
}
submit(){
this.dialogService.open({ viewModel: Prompt, model: this.person}).then(response => {
if (!response.wasCancelled) {
console.log('good');
} else {
console.log('bad');
}
console.log(response.output);
});
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app="main">
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-dialog');
aurelia.start().then(a => a.setRoot());
}
import { DialogController } from 'aurelia-dialog';
export class ModalController {
static inject = [DialogController];
constructor(dialogController) {
this.dialogController = dialogController;
this.settings = dialogController.settings;
}
ok(model) {
return this.dialogController.ok(model);
}
cancel(model) {
return this.dialogController.cancel(model);
}
}
import { DialogService } from 'aurelia-dialog';
export class ModalService {
static inject = [DialogService];
constructor(dialogService) {
this.dialogService = dialogService;
}
open(modalModel) {
return this.dialogService.open(modalModel);
}
}
<template>
<ai-dialog>
<ai-dialog-body>
<h2>Edit name</h2>
<input value.bind="person.name" />
</ai-dialog-body>
<ai-dialog-footer>
<button click.trigger="cancelButtonClick()">Cancel</button>
<button click.trigger="ok(person)">Ok</button>
</ai-dialog-footer>
</ai-dialog>
</template>
import {ModalController} from './modal-controller';
export class Prompt {
static inject = [ModalController];
constructor(modalController) {
this.modalController = modalController;
}
save() {
this.modalController.ok(result);
}
cancelButtonClick() {
this.modalController.cancel();
}
}
<template>
<h1>Test</h1>
<button click.trigger="createProjectButtonClick()">Open</button>
</template>
import {ModalService} from './modal-service';
export class Sample {
accountId = 1;
static inject = [ModalService];
constructor(modalService) {
this.modalService = modalService;
}
createProjectButtonClick() {
this.modalService.open({
viewModel: './prompt',
model: { accountId: this.accountId },
}).then(result => {
if(result.wasCancelled) {
return;
}
console.log(result);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment