Last active
January 4, 2018 08:11
-
-
Save pbishop16/1aa5e7e25a9f6b7244a2f4309fe8f94c to your computer and use it in GitHub Desktop.
Modifying the Model in the AfterModel Hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle', | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| const { | |
| assign, | |
| } = Ember; | |
| export default Ember.Route.extend({ | |
| model() { | |
| return { | |
| cards: [], | |
| otherData: null, | |
| }; | |
| }, | |
| afterModel(model) { | |
| const transactions = []; | |
| assign(model, { transactions }); | |
| /* Ember.set(model, key, value) provides a safe fallback if .set() is not available */ | |
| Ember.set(model, 'otherData', {}); | |
| console.log(model); | |
| /* Ember.get(model, key) provides a safe fallback if .get() is not available */ | |
| console.log(Ember.get(model, 'transactions')); | |
| /* model.get(key) will throw an error */ | |
| console.log(model.get('transactions')); | |
| }, | |
| setupController(controller, model) { | |
| this._super(...arguments); | |
| controller.setProperties(model); | |
| }, | |
| }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": "0.13.0", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "2.16.2", | |
| "ember-template-compiler": "2.16.2", | |
| "ember-testing": "2.16.2" | |
| }, | |
| "addons": { | |
| "ember-data": "2.16.3" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment