Skip to content

Instantly share code, notes, and snippets.

@Serabe
Forked from aonawale/controllers.application.js
Last active February 24, 2017 16:01
Show Gist options
  • Save Serabe/e3afc13d9a6fb5d37a3745a80640f421 to your computer and use it in GitHub Desktop.
Save Serabe/e3afc13d9a6fb5d37a3745a80640f421 to your computer and use it in GitHub Desktop.
queryParam map to different controller property
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
bookingValid() { return false }
});
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: ['quantity'],
quantity: 1
});
import Ember from 'ember';
export default Ember.Controller.extend({
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('checkout', function() {
this.route('payment')
})
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
});
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
quantity: {
as: 'qty'
}
},
});
import Ember from 'ember';
export default Ember.Route.extend({
beforeModel() {
this._super(...arguments);
let indexCtrl = this.controllerFor('checkout.index');
if (!indexCtrl.bookingValid()) {
this.replaceWith('checkout.index');
}
},
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{link-to "Click me" "checkout.payment" (query-params quantity=2)}}
{{outlet}}
<br>
<br>
checkout {{qty}}
<p>
{{outlet}}
</p>
{
"version": "0.11.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.8.3",
"ember-template-compiler": "2.8.3"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment