Skip to content

First change made to an item inside a meteorCollection after an update from server is not pushed to server #345

@cnelson711

Description

@cnelson711

The first change to an array is only registered locally and not pushed to the server if I use a $meteor.collection and try to push to an array that is a member of an item in the collection (I'm NOT saving or removing a new party from the collection, but editing an array that is a member of a party),

I've pasted my code below.

party.ng.js
============
angular.module('parties', ['angular-meteor', 'ui.router']);
angular.module('parties').controller('PartyController', function($scope, $meteor) {
    var ctrl = this;

    ctrl.newPartyName = "";
    ctrl.parties = $meteor.collection(Parties);

    ctrl.createParty = function() {
        ctrl.parties.save({
            name: ctrl.newPartyName,
            randomNumbers: []
        });
        ctrl.newLeagueName = '';
    };

    // Join a league (submit a request to join)
    ctrl.addToPartyArray = function(party) {
        party.randomNumbers.push(Math.random());
    };

    ctrl.removeFromPartyArray = function(party) {
        party.randomNumbers.splice(0, 1);
    };
});

index.ng.html
================
<div ng-controller="PartyController as partyCtrl">
    <ul>
        <li ng-repeat="party in partyCtrl.parties">{{party.name}}
            <p ng-repeat="num in party.randomNumbers">{{num}}</p>

            <button type="submit" ng-click="partyCtrl.addToPartyArray(party)">Add Random Num</button>
            <button type="submit" ng-click="partyCtrl.removeFromPartyArray(party)">Remove Random Num</button>
        </li>
    </ul>

    <form name="createPartyForm" ng-submit="createPartyForm.$valid && partyCtrl.createParty()" novalidate>
        <input ng-model="partyCtrl.newPartyName" type="text" placeholder="Party Name" required>
        <button type="submit" ng-class="{ disabled : !createLeagueForm.$valid }">Create Party</button>
    </form>
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions