Skip to content

Instantly share code, notes, and snippets.

@mastastealth
Created February 11, 2022 15:22
Show Gist options
  • Save mastastealth/41adb1e3c535839c92a1a4a3d562f7f3 to your computer and use it in GitHub Desktop.
Save mastastealth/41adb1e3c535839c92a1a4a3d562f7f3 to your computer and use it in GitHub Desktop.
Add to array
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@tracked items = []
@action
add() {
this.items = [...this.items, { name: "Foo" }];
}
}
<h1>Welcome to {{this.appName}}</h1>
<br>
{{#each this.items as |item|}}
{{item.name}}
{{/each}}
<br>
<button {{on "click" this.add}}>Add</button>
{{outlet}}
<br>
<br>
{
"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