Skip to content

Instantly share code, notes, and snippets.

@ASH-Bryan
Last active April 18, 2020 14:45
Show Gist options
  • Save ASH-Bryan/219fc6575cb7e748e4832c617dc2c630 to your computer and use it in GitHub Desktop.
Save ASH-Bryan/219fc6575cb7e748e4832c617dc2c630 to your computer and use it in GitHub Desktop.
Object depth
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle'
@service objectDepth
@action updateService() {
this.objectDepth.set('rootItem', 'newValue')
}
}
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
export default class ShoppingCartService extends Service {
@tracked rootItem = 'rootItem'
get subObject1() {
return {
subItem: this.rootItem
}
}
subObject2 = {
subItem: 'y'
}
}
<h1>Welcome to {{this.appName}}</h1>
<br>
<br>
<p>From root: {{this.objectDepth.rootItem}}</p>
<p>From sub1: {{this.objectDepth.subObject1.subItem}}</p>
<p>From sub2: {{this.objectDepth.subObject2.subItem}}</p>
<p><button {{on 'click' this.updateService}}>Update</button></p>
<br>
<br>
{
"version": "0.17.0",
"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.3.1/jquery.js",
"ember": "3.17.0",
"ember-template-compiler": "3.17.0",
"ember-testing": "3.17.0"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment