Model Promise with setupcontroller Test
{
"version": "0.7.2",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
}
}
<p>In Post {{model.id}}</p>
<p>Comment : </p>
<h1>Welcome to {{appName}}</h1>
<br>
{{#link-to 'posts'}}POST{{/link-to}}
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export default Ember.Route.extend({
/* beforeModel(params) {
alert(params.post_id);
return '1';
}, */ //params cannot be passed to beforeModel
redirect(model, transition) {
alert('redirect');
this.transitionTo('posts.post.comment', 1);
},
model() {
return new Ember.RSVP.Promise(function(resolve) {
Ember.run.later(function() {
resolve({ msg: 'Setup - child', id: 1});
alert('in post child');
}, 1000);
});
},
setupController(controller, model) {
alert(model.msg); // "Hold Your Horses"
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return new Ember.RSVP.Promise(function(resolve) {
Ember.run.later(function() {
resolve({ msg: 'Setup - comment', id: 1});
alert('in comment child');
}, 1000);
});
},
setupController(controller, model) {
alert(model.msg); // "Hold Your Horses"
}
});
import Ember from 'ember';
export default Ember.Route.extend({
redirect(model, transition) {
alert('redirect');
this.transitionTo('posts.post', 1);
},
afterModel() {
alert('POST: AF');
//this.transitionTo('posts.post', 1);
},
model() {
return new Ember.RSVP.Promise(function(resolve) {
Ember.run.later(function() {
resolve({ msg: 'Setup - Parent' });
alert('in post parent');
}, 1000);
});
},
beforeModel() {
alert('POST: BF');
},
setupController(controller, model) {
alert(model.msg); // "Hold Your Horses"
}
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none'
});
Router.map(function() {
this.route('posts', function() {
this.route('post', { path: ':post_id' }, function() {
this.route('comment', { path: ':comment_id' });
});
});
});
export default Router;
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});