I want to create a collection or model in a project Angular Ionic (like Backbonejs). Is it possible? If yes, can I use Backbone? If no, what can I do (the best way)? Thanks.
Typically in Angular, you would just use straight up vanilla JavaScript objects.
var person = {
firstName: "Andrew",
lastName: "McGivery"
}
And a collection would just be an array of these objects...
var person1 = {
firstName: "Andrew",
lastName: "McGivery"
}
var person2 = {
firstName: "Léon",
lastName: "Jiresse"
}
var people = [person1,person2];
//or
people = [];
people.push(person1,person2);
In a way, the architecture of Angular kind of assumes you are getting your models from the backend (a server, webservice, etc) via $http.
app.factory("PeopleService",function(){
return {
GetPeople: function(){
return $http.get('path/to/backend/people');
}
}
}
app.controller("PeopleController",function($scope,PeopleService){
PeopleService.GetPeople().then(function(people){
$scope.people = people;
});
});
More Reading Material: http://www.wekeroad.com/2013/04/25/models-and-services-in-angular/