Skip to content

Instantly share code, notes, and snippets.

@glen-84
Forked from jdanyow/app.html
Last active August 21, 2017 17:25
Show Gist options
  • Save glen-84/285933c1cb0e2ff4b7fe67879db946ae to your computer and use it in GitHub Desktop.
Save glen-84/285933c1cb0e2ff4b7fe67879db946ae to your computer and use it in GitHub Desktop.
Aurelia set select options and value
<template>
<h1>Instructions</h1>
<ol>
<li>Click the "Set value" button (selected option changes correctly)</li>
<li>Increment number to 3</li>
<li>Click the "Set options and value" button (selected option is not set correctly)</li>
</ol>
<select value.bind="matchGame.winner.id">
<option model.bind="null" value="">(please select)</option>
<option model.bind="matchGame.opponent1.id">${matchGame.opponent1.name}</option>
<option model.bind="matchGame.opponent2.id">${matchGame.opponent2.name}</option>
</select>
Val: ${matchGame.winner.id}
<br />
<br />
<input type="number" value="2" ref="val" />
<button click.trigger="setValue(val.value)">Set value</button>
<button click.trigger="setOptionsAndValue(val.value)">Set options and value</button>
</template>
export class App {
message = 'Hello World!';
matchGame = {
opponent1: {
id: 1,
name: "opp1"
},
opponent2: {
id: 2,
name: "opp2"
},
winner: {
id: 1
}
};
setValue(val) {
this.matchGame.winner.id = parseInt(val, 10);
}
setOptionsAndValue(val) {
this.matchGame = {
opponent1: {
id: 3,
name: "opp3"
},
opponent2: {
id: 4,
name: "opp4"
},
winner: {
id: parseInt(val, 10)
}
};
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment