Skip to content

Instantly share code, notes, and snippets.

@neborn
Created October 9, 2020 17:39
Show Gist options
  • Save neborn/8b9bf6817d263d885666b00668284664 to your computer and use it in GitHub Desktop.
Save neborn/8b9bf6817d263d885666b00668284664 to your computer and use it in GitHub Desktop.
Tracked Query Params
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class ApplicationController extends Controller {
queryParams = ['appName'];
@tracked
appName = 'Ember Twiddle';
get heading() {
return `Welcome to ${this.appName}`;
}
@action
updateAppName() {
if (this.appName == 'Foo Bar') {
this.appName = 'Ember Twiddle';
} else {
this.appName = 'Foo Bar';
}
}
}
import { helper } from '@ember/component/helper';
export default helper(function eq(params/*, hash*/) {
return params[0] === params[1];
});
<h1>{{this.heading}}</h1>
<button {{on "click" this.updateAppName}}>
Update app name
</button>
<LinkTo @route="application" @query={{hash appName=(if (eq this.appName "Other") "Not Other" "Other")}}>Update app name</LinkTo>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment