i am using angular.js with rails as my backend and i am encountering problem while updating the value of a scope variable inside the view. here i am trying to create a shopping cart kind of a thing.
html code
<div class="modal hide fade" id="orderForm">
<div class="modal-header">
<h3>
Please enter your location details <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</h3>
</div>
<div class="modal-body scrollable">
<form accept-charset="UTF-8" class="simple_form form-horizontal" name="orderForm" novalidate="novalidate" ng-submit="validateAndSubmit(orderForm)" id="order_form">
<div class="control-group string optional order_full_name">
<label class="string optional control-label" for="order_full_name">Full name</label>
<div class="controls">
<input class="string optional required " id="order_full_name" name="full_name" ng-model="full_name" placeholder="eg. Kapil Sharma" size="50" type="text" value="">
</div>
</div>
</div>
<div class="modal-footer">
<a href="" data-dismiss="modal" aria-hidden="true" class="btn">
Close
</a>
<button type="submit" class="btn btn-success"> <i class="icon-ok"></i> Place order</button>
<%# end %>
</form>
</div>
this is a bootstrap modal and is called with $('#orderForm').modal('show');
here is my javascript angular code.
$scope.validateAndSubmit = function(form){
if(form.$valid){
var formData = $('#order_form').serializeObject();;
$http.post('/create_order',{'order': formData})
.success(function(data,status){
$scope.currentOrder = data;
$('#orderForm').modal('hide');
$scope.currentOrder = [];
}).error(function(data,status){
//show error
alert("error");
});
}
else{
alert("invalid form");
}
}
the problem is with my scope variable $scope.currentOrder, in all other functions its working fine but in validateAndSubmit method its not updating the view as required i have checked the value of the scope variable by using the javascript setInterval method
setInterval(function(){
alert($scope.currentOrder);
}
, 5000);
the updated value is fine in alert but the view is not updating the value, please help. Thanks in advance.
currentOrder = dataand then two lines downcurrentOrder = []Is that correct? Provide more code or a jsfiddle.net for help$scope.currentOrder = []?