This is my router.js code.
this.route('contact',{'path': '/contact/:chat_id'});
and This is my route.js code.
model(params) {
return this.store.findRecord("chat", params.chat_id)
},
and This is my controller.js code and can i use like this. It shows error as null value please help me. How to use params in controller
recordChat: function() {
var chat = this.get(params.chat_id)
Ember.RSVP.hash({
offer_id: chat,
})
}
import ActivatedRoute from '@angular/router'. Inject ActivatedRoute class in constructor. Access queryParams property of ActivatedRoute class which returns an observable of the query parameters that are available in the current URL route.
Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed.
EmberJS - Query Parameters Query parameters are specified on route driven controllers which appear to the right of the ? in a URL and are represented as optional key-value pairs. The above URL has the two query parameters; one is sort and the other is page which contains values ASC and 2 respectively.
The Route Query tool allows you to check where packets with a certain IP address are routed according to the current definitions. You can check that the routing is correct and quickly find a particular branch in the Routing tree.
Edited for 2021: There's actually probably a much simpler way to do this now in Ember. See https://guides.emberjs.com/v3.27.0/routing/query-params/
Original Answer
I think the simplest answer is to create a variable in route and then set it in the setupController:
your_route.js
export default Ember.Route.extend({
model(params) {
this.set('myParam',params.my_Params);
// Do Model Stuff...
},
setupController(controller, model) {
// Call _super for default behavior
this._super(controller, model);
// Implement your custom setup after
controller.set('myParam', this.get('myParam'));
}
});
In your route.js, you need to call the setupController function like this:
setupController(controller, model) {
this._super(...arguments);
controller.set('chat', model);
}
Now you have access to it in your controller by calling:
recordChat() {
const chat = this.get('chat');
// if you don't call the setupController function, you could also do:
// const chat = this.get('model') or this.get('model.id') if you want the id only
}
UPDATE:
See working twiddle here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With