Last active
December 8, 2015 17:51
-
-
Save awilson28/cce98cbccbacb4b199c6 to your computer and use it in GitHub Desktop.
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.factory('AlbumFactory', function(DS, $state){ | |
// defining a Js-Data resource | |
var AlbumFactory = DS.defineResource({ | |
basePath: 'api', // what string prepends each uri ? | |
name: 'albums', // basePath + name = endpoint ('api/albums') | |
idAttribute: '_id', // where on the object is the primary key stored? | |
methods: { | |
go: function(){ | |
// transition to songs state | |
$state.go('songs', {_id: this._id}) | |
} | |
} | |
}) | |
return AlbumFactory; | |
}) | |
.controller('AlbumController', function(AlbumFactory){ | |
// GET to 'api/albums' | |
AlbumFactory.findAll() | |
.then(function(albums){ | |
var firstAlbum = albums[0] | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment