Skip to content

Instantly share code, notes, and snippets.

@krimple
Created January 28, 2015 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krimple/536095a76c383b5b4df6 to your computer and use it in GitHub Desktop.
Save krimple/536095a76c383b5b4df6 to your computer and use it in GitHub Desktop.
Using angular.copy for modal fetch and update of data
angular.module('myApp').service('greeterService',
['$log', function($log) {
var namesSpokenTo = [];
this.sayHello: function(name) {
namesSpokenTo.push(name);
$log.debug('hello, ' + name);
};
this.getNames = function() {
return angular.copy(namesSpokenTo);
};
this.replaceNames = function(names) {
angular.copy(names, namesSpokenTo);
}
}]);
// erase all elements of the array - doesn't
// destroy the original, just the copy sent
// by getNames().
greeterService.getNames().length = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment