Created
November 19, 2019 16:14
-
-
Save dagtveit/438e186bf7e5e7e2bc55f885eab321a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | |
</head> | |
<body> | |
<div aurelia-app="src/configure"> | |
Loading... | |
</div> | |
<script src="https://rawgit.com/aurelia-ui-toolkits/demo-materialize/gh-pages/jspm_packages/system.js"></script> | |
<script src="https://rawgit.com/aurelia-ui-toolkits/demo-materialize/gh-pages/jspm.config.js"></script> | |
<script> | |
System.import("aurelia-bootstrapper"); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<md-lookup value.bind="value" options-function.bind="optionsFunction" display-field-name.bind="getDisplayName" label="pick an option"> | |
<template replace-part="option-template"> | |
<span style="color: blue">${option.id}</span> - | |
<span>${option.name}</span> | |
</template> | |
<template replace-part="searching-template"> | |
Wait for 1 sec... | |
</template> | |
<template replace-part="no-matches-template"> | |
Didn't find anything | |
</template> | |
</md-lookup> | |
You picked: ${value | stringify} | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { observable } from "aurelia-binding"; | |
import { ILookupOptionsFunctionParameter } from "aurelia-materialize-bridge"; | |
interface ICompany { | |
id: number; | |
name: string; | |
} | |
export class App { | |
companies: ICompany[] = [{ id: 1, name: "Microsoft" }, { id: 2, name: "Google" }, { id: 3, name: "Apple" }]; | |
value: ICompany = this.companies[0]; | |
optionsFunction(p: ILookupOptionsFunctionParameter<ICompany>): Promise<ICompany[]> { | |
if (p.value) { | |
return Promise.resolve([p.value]); | |
} | |
else { | |
return this.searchCompanies(p.filter); | |
} | |
} | |
searchCompanies(filter: string): Promise<any[]> { | |
return new Promise<any[]>((resolve, reject) => { | |
setTimeout(() => resolve(this.companies.filter(x => x.name.includes(filter) || x.id.toString().includes(filter))), 1000); | |
}); | |
} | |
setValue() { | |
this.value = this.companies[2]; | |
} | |
getDisplayName(x: ICompany){ | |
return `${x.name} (id=${x.id})`; | |
} | |
} | |
// tslint:disable-next-line:max-classes-per-file | |
export class StringifyValueConverter { | |
toView(value) { | |
return JSON.stringify(value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function configure(aurelia) { | |
await aurelia.loader.loadModule("materialize-css"); | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging() | |
.plugin("aurelia-materialize-bridge", bridge => bridge.useAll()) | |
.plugin("aurelia-validation") | |
.globalResources("src/shared/logger"); | |
await aurelia.start(); | |
aurelia.setRoot("src/app"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment