Skip to content

Instantly share code, notes, and snippets.

@chintanparikh
Created November 7, 2014 10:24
Show Gist options
  • Save chintanparikh/a58d65195ddb0a27a3fd to your computer and use it in GitHub Desktop.
Save chintanparikh/a58d65195ddb0a27a3fd to your computer and use it in GitHub Desktop.
App.controller("VideosController", [ '$scope', '$routeParams', '$location', 'Video',
($scope, $routeParams, $location, Video) ->
$scope.videos = Video.all()
$scope.search = () ->
search_result = Video.search($scope.searchTerms)
if $scope.searchTerms
unless $scope.videos == search_result
$scope.videos = search_result
else
$scope.videos = Video.all()
App.factory 'Video', ['$resource', ($resource) ->
allVideos = () ->
$resource('/videos.json').query()
search = (terms) ->
$resource('/videos/search/:search_terms').query({search_terms: terms})
return {
all: allVideos,
search: search
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment