Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Last active August 29, 2015 13:56
Show Gist options
  • Save dhigginbotham/8957914 to your computer and use it in GitHub Desktop.
Save dhigginbotham/8957914 to your computer and use it in GitHub Desktop.
var app = app || angular;
app.factory('photos', ['$rootScope', function ($rootScope) {
var photos = {};
photos.add = function (mixed) {
if (mixed instanceof Array) {
for (var i=0;i<mixed.length;++i) {
photos.data.push(mixed[i]);
}
} else photos.data.push(mixed);
$rootScope.$broadcast('photos:added', photos.data); // this is just an example of passing custom events
};
photos.del = function (index) {
photos.data.splice(index,1);
$rootScope.$broadcast('photos:deleted', photos.data); // this is just an example of passing custom events
};
return photos;
}]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment