I found this related topic, where the answer suggests to watch for the model change instead of the change of the select. But in my example the "model" is part of an object inside a list. Is the correct way to initialize $watch
for every object in the list?
Select
<li data-ng-repeat="obj in main.list track by $index">
<select data-ng-change="main.changeStatus(obj)" data-ng-model="obj.status">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</li>
changeStatus
I need to update the object or already receive the correct object in the change method.
main.changeStatus = function(obj) {
var r = new Resource(obj);
...
r.$save({...}, function (savedObj) {
...
});
}
What's the correct way to solve this issue?
thanks
Edit: I guess I didn't ask the correct question.
The posted code doesn't achieve what I am looking for, because the change method gets executed before the model is updated, therefore I send the incorrect/old object to the backend. Now there are a couple of ways to fix that
Idealy I get the new object to the change method, but I don't know how.
Edit2: I tried to write a fiddle to make it clear, but it works there. I need to look deeper into my code, because the problem seems to be somewhere else.
lets clarify your problem , you have 5 dropdowns , with each you have 3 options a,b,c , and you want to do what in a clear way? if you mean list object in main.list by saying "update the object or already receive the correct object in the change" then your code is ok.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With