Currently facing an issue that needs to be addressed:
app.controller 'MainCtrl', ($scope, TestData) ->
$scope.name = 'World'
TestData.get(0).then (data)->
$scope.elem = data
TestData.get(1).then (data)->
$scope.elem2 = data
$scope.callFunc = ->
TestData.modify1()
TestData.modify2()
app.factory 'TestData', ($q,$timeout)->
data = [{
name: "TestData #1"
id: 1
},{
name: "TestData #2"
id: 2
}]
funcs = {}
funcs.get = (id)->
deferred = $q.defer()
$timeout(->
deferred.resolve(data[id])
,500)
return deferred.promise
funcs.modify1 = ->
data[0].name = "DataTest #1"
funcs.modify2 = ->
data[1] = {
name: "DataTest #2"
id
}
return funcs
In an attempt to update an element in an array, I find myself unsure of the best approach. It seems that simply replacing it will not solve the problem. How can this obstacle be overcome?
If it were a matter of just altering the name/id, there wouldn't be an issue. However, the models contain a variety of data that I wish to update collectively without modifying them individually.
A demonstration illustrating the issue can be found here: http://plnkr.co/edit/cBXJsIghlIeIUQGLfZfe?p=info
(Despite understanding the underlying reason for the difficulty, I am seeking the most efficient solution to resolve this predicament.)