how you manage models relations with angular? It is very easy in Ember, but how to deal with it in angular and not produce bunch of messy code?
I use https://github.com/klederson/ModelCore/ it's very simple and easy to use
var ExampleApp = angular.module('ExampleApp', ['ModelCore']); //injecting ModelCore
ExampleApp.factory("Users",function(ModelCore) {
return ModelCore.instance({
$type : "Users", //Define the Object type
$pkField : "idUser", //Define the Object primary key
$settings : {
urls : {
base : "http://myapi.com/users/:idUser",
}
},
$myCustomMethod : function(info) { //yes you can create and apply your own custom methods
console.log(info);
}
});
});
And then i just need to inject into my controller and use it
function MainCrtl($scope, Users) {
//Setup a model to example a $find() call
$scope.AllUsers = new Users();
//Get All Users from the API
$scope.AllUsers.$find().success(function() {
var current;
while(current = $scope.AllUsers.$fetch()) { //fetching on masters object
console.log("Fetched Data into Master Object",$scope.AllUsers.$toObject()) //reading fetched from master
//or just get the fetched object itself
console.log("Real fetched Object",current.$toObject())
}
});
Angular doesn't have a "data store" layer like ember-data, but you can integrate any existing ORM if you'd like to - Which JavaScript ORM to use?