I'm trying to connect (in Angular, at the client) the same database object through its html view, to its equivalent instance through a json API.
I have a working api and $resource, and have a working view, I just can't figure out how to create the binding, so that updates to the view update the Angular model / $resource.
Specifically, I have an html view populated server side that contains an ngBind attribute:
<div class="ng-scope" ng-app="Posts">
<div class="ng-scope" ng_controller="PostsCtrl">
<span contenteditable="true" ng-bind="post.1.text">post.1.text value</span>
</div>
</div>
There are several of these on the page with unique ids.For the purpose of the example, if it's easier to think of this as a form text field, then ignore 'contenteditable', an I'll deal with that part separately.
The format of that attribute is flexible, that's just how it is currently (i.e. post.1.text could be post_1_text, or split up entirely as needed.)
The resource factory looks like this (coffee script, but answers in js equally gratefully received!:
app = angular.module 'Posts', ['ngResource']
app.factory 'Post', ($resource) ->
$resource('/api/posts/:id', {id: '@id'})
app.controller "PostsCtrl", @PostsCtrl = ($scope, Post) ->
$scope.posts = Post.query()
which successfully populates a posts collection (not needed for this example, but shows the API is working).
So, what should ng-bind look like, and how to bind the controller to get updates to the view written back to the API?
(I know I could just use ng_repeat: "post in posts"
, but just go with me that I really do want to do this. "It's complicated" :-)
Thanks!
Edit: Here's a jsfiddle that shows roughly what I'm trying to achieve:
...but i'd like the id to bind to the object key 'id' rather than to the index of the object in the array.