Created
January 28, 2015 19:33
-
-
Save krimple/536095a76c383b5b4df6 to your computer and use it in GitHub Desktop.
Using angular.copy for modal fetch and update of data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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