Last active
December 17, 2015 16:59
-
-
Save kylewelsby/5643171 to your computer and use it in GitHub Desktop.
Association resource.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = angular.module('app', ['ngResource']) | |
app.factory("Result", ["$resource", ($resource) -> | |
$resource("/scrapes/:scrape_id/results/:id", {scrape_id: "@scrape_id", id: "@id"}) | |
]) | |
app.controller("MainCtrl", ['$scope','Result',($scope,Result)-> | |
$scope.scrape = {id: 1} | |
$scope.results = [] | |
$scope.getResults = (-> | |
Result.get(scrape_id: $scope.scrape.id,(obj)-> | |
# onSuccess | |
$scope.results = obj | |
,(obj)-> | |
# onFailure | |
alert("Failed with: #{obj.data}") | |
) | |
) | |
$scope.getResult = ((id)-> | |
Result.query({scrape_id: $scope.scrape.id, id: id},(obj)-> | |
# onSuccess | |
$scope.results = obj | |
,(obj)-> | |
# onFailure | |
alert("Failed with: #{obj.data}") | |
) | |
) | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment