新しく追加された項目をhttp.postedにした後に、それをプッシュするための正しい構文を見つけようとしています。
以下の構文ではエラーは表示されませんが、正しく押されません。すべてのアイデアは
$scope.insertAppointmentReminderEntry = function() {
$scope.add_reminder_time = this.add_reminder_time;
$scope.add_reminder_timeunit = this.add_reminder_timeunit;
$scope.add_delivery_method = this.add_delivery_method;
$scope.add_delivery_contact = this.add_delivery_contact;
var data = {
group_id : $scope.groupid,
appointment_id : $scope.appointmentid,
reminder_time : $scope.add_reminder_time,
reminder_timeunit : $scope.add_reminder_timeunit,
delivery_method : $scope.add_delivery_method,
delivery_contact : $scope.add_delivery_contact
};
$http.post(urlApiAppointmentReminders + $scope.groupid, data).success(function(data, status) {
var newItemNo = $scope.appointmentreminders.length+1;
$scope.appointmentreminders.push($scope.appointmentreminders[newItemNo].data);
})
modalInstance.close();
};
HTML
<div ng-repeat="x in appointmentreminders" class="row" ng-style="{ 'border-top' : (x.delivery_method != appointmentreminders[$index-1].delivery_method && $index != 0 ? '1pt solid #eee' : '0pt solid #eee')}" style="border-top:1pt solid #eee; padding: 0.25em 0 0.25em 0" >
<div class="col-md-offset-1 col-md-4">
@{{x.time}} @{{x.timeunit}}@{{x.time > 1 ? 's' : ''}} prior to appointment
</div>
<div class="col-md-4">
Reminder: @{{x.delivery_contact}}
</div>
<div class="col-md-2">
<!-- delete this reminder -->
<a class="btn btn-xs btn-warning pull-right glyphicon glyphicon-trash" ng-click="ctrl.removeItem($index)"></a>
</div>
</div> <!-- ng-repeat -->
HTML(新しいリマインダーを追加するモーダル)
<script type="text/ng-template" id="addScheduleModalContent.html">
<div class="modal-header">
<h3 class="modal-title">Add a new appointment reminder</h3>
</div>
<div class="modal-body">
<div class="row" style="padding: 0.5em 0 0.5em 0.5em">
<div class="col-sm-4" >
{!! Form::text('reminder_time', '30', ['class' => 'form-control', 'placeholder' => '', 'ng-model' => 'add_reminder_time']) !!}
</div>
<div class="col-sm-8" >
{!! Form::select('reminder_timeunit', ['minute' => 'minutes(s)', 'hour' => 'hour(s)', 'day' => 'day(s)', 'week' => 'week(s)', 'month' => 'month(s)'], null, ['class' => 'form-control', 'ng-model' => 'add_reminder_timeunit']) !!}
</div>
</div>
<div class="row" style="padding: 0.5em 0 0.5em 0.5em">
<div class="col-sm-4" >
{!! Form::select('delivery_method', ['eml' => 'Email'], null, ['class' => 'form-control', 'ng-model' => 'add_delivery_method']) !!}
</div>
<div class="col-sm-8" >
{!! Form::text('delivery_contact', null, ['class' => 'form-control', 'placeholder' => 'Your email address', 'ng-model' => 'add_delivery_contact']) !!}
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="insertAppointmentReminderEntry()">Save</button>
<button class="btn btn-primary" ng-click="$close()">Close</button>
</div>
</script>
でそれらを結合していません。オブジェクトを配列にプッシュしたくないのですか? – charlietfl
私はあなたが正しいと確信しています、私は少しjsで失われる。例えば、$ scope.add_reminder_timeを$ scope.reminder_timeに変更してAPI名に一致させることを意味します。 – user3489502
'ng-model =" reminder.time "' ... 'ng-model =" reminder.contact ".. .. etc ...' $ http.post'に '$ scope.reminder'を送り、プロパティと個々の変数名を手動でコピーするのをスキップします – charlietfl