Skip to content

Instantly share code, notes, and snippets.

@rileyhilliard
Last active July 15, 2021 00:30
Show Gist options
  • Save rileyhilliard/87a86e9d9b4f78ff3270fed996cbe656 to your computer and use it in GitHub Desktop.
Save rileyhilliard/87a86e9d9b4f78ff3270fed996cbe656 to your computer and use it in GitHub Desktop.
Parent Child model data lookup
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
import Controller from '@ember/controller';
export default Controller.extend({
actions: {
setParent() {
// set a property on the parent controller
debugger;
const controller = this.controllerFor('parent');
debugger;
}
}
});
import Controller from '@ember/controller';
export default Controller.extend({
enabled: false
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('parent', function () {
this.route('child')
});
});
export default Router;
import Route from '@ember/routing/route';
export default Route.extend({
model() {
const parent = this.modelFor('parent');
parent.data = 'changed';
return parent;
},
});
import Route from '@ember/routing/route';
export default Route.extend({
model() {
return {
data: 'I am data that was fetched from the parent'
}
}
});
<h1>Welcome to {{this.appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<br>
I am the child route<br>
{{model.data}}
<button {{action "setParent"}}> toggle</button>
I am the parent route
<br>
{{model.data}}
{{#if enabled}}
<br>I am enabled
{{else}}
<br>I am not enabled
{{/if}}
{{outlet}}
{
"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