lundi 14 novembre 2016

Why is Angular http.post converting string value to an array?

I have an Angular js and Laravel app. One of my form feilds is an ng-options driven select. The values are strings but when I post using http.post, one of the values seems to be getting converted to an array.

I have this in my js controller for the options;

    $scope.periods = [
    {label: '1'},
    {label: '2'},
    {label: '3'},
    {label: 'OT'}
];

This is my view for the select;

<select ng-model="egoal.period"
        ng-options="period.label as period.label for period in periods"
        class="form-control game-control"
        required>
</select>

And then this in the controller to post;

  $scope.changeGoal = function() {
        var egoal = this.egoal;
        $http.post('api/editGoal/' + this.goal.id, egoal)
            .success(function () {
                $scope.egoal = {};
            });
};

Oddly, when I dump the $request, I get period => [] and then this error;

ErrorException in helpers.php line 685: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

Been looking at this for a long time now. What could be causing this? Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire