How to save Firebase objects $asArray() with angularFire, when the objects contain ng-repetate

后端 未结 1 1140
暗喜
暗喜 2021-02-10 15:50

I recently switched from angularfire 0.6 to to 0.8.0. I am having problems to save an item of a list, that contains an array itself.

My Objects account

相关标签:
1条回答
  • 2021-02-10 16:29

    Of course the best way to solve it in firebase like @Kato mentioned and have the real time binding to data from array into view you should use an extra firebase synchronized object through the $asArray instance.

    Like in this solution: http://jsfiddle.net/RaVbaker/sb00kor8/1/ But you will loose then possibility to save data "on demand" with button like Save to Firebase. They will be saved instantly after change in firebase array object occurs. But it will also give you flexibility and synchronization of data across pages.

    But other and much easier in your case is to change the way angular tracks uniqueness of objects in ng-repeat directive. It can be done by setting track by $index in the end of ng-repeat statement.

    Changing ng-repeat="duration in account.durations" into this:

     ng-repeat="duration in account.durations track by $index"
    

    Your jsfiddle updated with this solution: http://jsfiddle.net/RaVbaker/sb00kor8/2/

    More info about track by for ngRepeat you can find obviously in official documentation.

    Hope I helped.

    0 讨论(0)
提交回复
热议问题