Skip to content

Instantly share code, notes, and snippets.

@GCheung55
Last active August 30, 2018 18:34
Show Gist options
  • Save GCheung55/914dbf8547bdeaa24891b04f54df3810 to your computer and use it in GitHub Desktop.
Save GCheung55/914dbf8547bdeaa24891b04f54df3810 to your computer and use it in GitHub Desktop.
Demonstrate setting value on service when query param changes
import Ember from 'ember';
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
export default Ember.Controller.extend({
mobileView: service(),
appName: 'Ember Twiddle',
queryParams: [ 'webview' ],
webview: alias('mobileView.isWebview'),
actions: {
toggleWebview() {
this.toggleProperty('webview');
}
}
});
import Ember from 'ember';
import { readOnly } from '@ember/object/computed';
import { computed, get, set } from '@ember/object';
export default Ember.Service.extend({
isWebview: false
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
Controller: {{webview}}<br>
Service: {{mobileView.isWebview}}<br>
<button type="button" {{action "toggleWebview"}}>Toggle webview query param</button>
{
"version": "0.15.0",
"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.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment