+

js-data logo

js-data-angular bower version npm version Circle CI npm downloads License @@ -97,39 +88,39 @@

Load js-data-angular.js after js-data.js.

-
angular.module('myApp', ['js-data']);
+
angular.module('myApp', ['js-data']);
-
angular.module('myApp').factory('Post', function (DS) {
-  return DS.defineResource('post');
+
angular.module('myApp').factory('Post', function (DS) {
+  return DS.defineResource('post');
 });
-angular.module('myApp').factory('Comment', function (DS) {
-  return DS.defineResource('comment');
+angular.module('myApp').factory('Comment', function (DS) {
+  return DS.defineResource('comment');
 });
-
app.controller('postCtrl', function ($scope, $routeParams, Post, Comment) {
+
app.controller('postCtrl', function ($scope, $routeParams, Post, Comment) {
   // it's up to your server to know how to interpret this query
   // or you can teach js-data how to understand your servers' query language
-  var query = {
-    postId: $routeParams.id
+  var query = {
+    postId: $routeParams.id
   };
 
-  Post.find($routeParams.id);
+  Post.find($routeParams.id);
   Comment.findAll(query);
 
   // My goodness this was easy
-  Post.bindOne($routeParams.id, $scope, 'post');
-  Comment.bindAll(query, $scope, 'comments');
+  Post.bindOne($routeParams.id, $scope, 'post');
+  Comment.bindAll(query, $scope, 'comments');
 
   // Long form (same effect as above)
-  $scope.$watch(function () {
-    return Post.lastModified($routeParams.id);
-  }, function () {
-    $scope.post = Post.get($routeParams.id);
+  $scope.$watch(function () {
+    return Post.lastModified($routeParams.id);
+  }, function () {
+    $scope.post = Post.get($routeParams.id);
   });
-  $scope.$watch(function () {
+  $scope.$watch(function () {
     // Changes when anything in the Comment collection is modified
-    return Comment.lastModified();
-  }, function () {
+    return Comment.lastModified();
+  }, function () {
     $scope.comments = Comment.filter(query);
   });
 });
@@ -193,13 +184,16 @@

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-