angularjs - Angular update object in array -
I want to update an object within an object array. Is there any other possibility to update the one running and matching on all things? The current code looks like the following:
Angular Module ('app'). Controller ('MyController', function ($ scope) {$ scope.object = {name: 'test', objects: [[id: 1, name: 'test1'}, {id: 2, name: 'test2'} }} $ Scope.update = function (id, data) {var object = $ scope.object.objects; (var i = 0; i
There are several ways to do this: Your situation is not very clear.
-> You can pass an index instead of an id. After that, your update function will be as follows:
$ scope.update = function (index, data) {$ Scope.object.objects [index] = data; };
-> You can use ng-repeat on your view and you can tie object elements into input elements.
& lt; Div ng-repeat = "item in object.objects" & gt; ID: & lt; Input ng-model = "item.id" /> & Lt; Br / & gt; Name: & lt; Input ng-model = "item.name" /> & Lt; Br / & gt; & Lt; / Div & gt;
Comments
Post a Comment