@mohsalim wrote:
app/template/post.hbs:
<div> {{input type="text" value=newTitle class="form-control" placeholder="Enter title" autofocus="autofocus"}} {{input type="text" value=newBody class="form-control" placeholder="Enter text" autofocus="autofocus"}} <div class="col-xs-10 col-xs-offset-1 col-sm-offset-0 col-sm-4 col-md-3"> <button class="btn btn-primary btn-lg btn-block" {{action 'saveBlogPost'}}>Submit</button> </div> </div> <div> {{#each post in model}} <div> <div>{{post.title}}</div> <div>{{post.body}}</div> </div> {{/each}} </div>
app/models/post.js:
import DS from 'ember-data'; export default DS.Model.extend({ title: DS.attr('string'), body: DS.attr('string') });
app/routes/post.js:
import Ember from 'ember'; export default Ember.Route.extend({ model: function() { //tried without without .then and without reload: true. no luck. return this.store.findAll('post', {reload: true}).then( function(result) { return result; }); } });
app/controllers/post.js:
import Ember from 'ember'; export default Ember.Controller.extend({ newTitle: '', newBody: '', actions: { saveBlogPost() { const newPost = this.store.createRecord('post', { title: this.get('newTitle'), body: this.get('newBody') }); newPost.save(); } } });
In ember inspector, there are 8 post model entries in firebase. However, when I go to http://localhost:4200/posts, only the top divider appears and not the bottom one (with #each helper). What am I doing wrong? I can actually store data with the text fields and button on the top divider.
C:\project-path>ember -v version: 2.4.2 node: 4.4.0 os: win32 ia32
Posts: 1
Participants: 1