One advantage of a controller is storing properties. Controllers have properties that are stored in the application, which is unlike the model where properties are saved to the server. In this recipe, we'll take a look at a few different types of properties and how they can be displayed in a template.
In a new application, run the following command:
$ ember g controller application
In this application, we'll be using the
application controller
to store all our properties.Update the application controller to add a new action and a few properties:
// app/controllers/application.js import Ember from 'ember'; export default Ember.Controller.extend({ prop2: 'test', prop3: true, actions: { enter(val){ alert(this.get('prop1')); alert(this.getProperties('prop1','prop2').prop1); alert(val); this.toggleProperty('prop3'); } } });
This controller has two properties. The first property contains a string...