Skip to content

Instantly share code, notes, and snippets.

@rtablada
Last active January 3, 2019 22:52
Show Gist options
  • Save rtablada/bad1dd32c81f9c4d93864cd0a59e19ac to your computer and use it in GitHub Desktop.
Save rtablada/bad1dd32c81f9c4d93864cd0a59e19ac to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
export default Ember.Controller.extend({
router: service(),
appName: 'Ember Twiddle',
value: 0,
queryParams: ['value', 'value2'],
isActive0: computed('router.currentURL', function() {
return this.router.isActive('index', { queryParams: {
value: 0
} });
}),
isActive1: computed('router.currentURL', function() {
return this.router.isActive('index', { queryParams: {
value: 1
} });
}),
isActive2: computed('router.currentURL', function() {
return this.router.isActive('index', { queryParams: {
value: 2
} });
}),
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
button {
font-size: 1.2rem;
}
button.active {
background: blue;
color: white;
}
<h1>Click on a Button To See if Active</h1>
<p>Value = {{value}}</p>
<p>
<button onclick={{action (mut value) 0}} class="{{if isActive0 'active'}}">Pick = 0</button>
<button onclick={{action (mut value) 1}} class="{{if isActive1 'active'}}">Pick = 1</button>
<button onclick={{action (mut value) 2}} class="{{if isActive2 'active'}}">Pick = 2</button>
</p>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment