Advertisement
Guest User

Untitled

a guest
May 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import Ember from 'ember';
  2. import { computed } from '@ember/object';
  3.  
  4. export default Ember.Controller.extend({
  5. appName: 'Ember Twiddle',
  6. currentCity: undefined,
  7. cityToBeRemoved: undefined,
  8. cities: ['London', 'Rome', 'Los Angeles'],
  9.  
  10. // it's important to listen on elements added or removed with cities.[]
  11. citiesFirstLetter: computed('cities.[]', function() {
  12. return this.cities.map((item) => {
  13. return item[0];
  14. });
  15. }),
  16.  
  17. location: {
  18. streetName: 'Caledonian Road',
  19. streetNumber: '233',
  20. },
  21.  
  22. address: computed('location.{streetName,streetNumber}', function() {
  23. return `${this.location.streetNumber} ${this.location.streetName}`;
  24. }),
  25.  
  26. actions: {
  27. addCity(name) {
  28. console.log(name);
  29. // it's important to use observable methods like pushObject instead of push otherwise the other properties will not recomputed
  30. this.cities.pushObject(name);
  31. },
  32. removeCity(name) {
  33. this.cities.removeObject(name);
  34. },
  35. changeLocation() {
  36. this.set('location.streetName', 'Kings cross');
  37. // this.set('location.streetNumber', '000');
  38. // this.set('location', { streetName: 'Carnaby Street', streetNumber: 22 });
  39. }
  40. }
  41. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement