- STEP 1: npm install js-data and js-data-angular in that order
- STEP 2: list js-data as a dependency and set default values (DSProvider is the name of the DS object in the config step):
var app = angular.module('nameOfApp', ['js-data'])
.config(function(DSProvider) {
DSProvider.defaults.basePath = '/api';
DSProvider.defaults.idAttribute = '_id';
})
- STEP 3: inject the DS object into a factory
app.factory('Post', function(DS) { })
- STEP 4: start building factories
app.factory('Post', function(DS, $state) {
var Post = DS.defineResource({
name: 'posts',
relations: {
belongsTo: {
users: {
localKey: 'author',
localField: '_author'
}
}
},
methods: {
go: function(){
$state.go('post', {
postId: this._id,
authorId: this.author
})
}
}
})
return Post;
}).run(function (Post) {})