Javascript 未通过$http.post发送角度$scope变量。为什么?
我错过了什么把戏吗?我正在构建一个json,甚至在页面内对其进行测试,以确保将值分配给正确的范围变量,但当我发送对象时,它接收到null或未定义的变量。请忽略console日志对象中的会话变量,它来自sessionStorage。我在其他控制器中成功地完成了$http.post,但这一个让我感到困惑 控制员:Javascript 未通过$http.post发送角度$scope变量。为什么?,javascript,angularjs,Javascript,Angularjs,我错过了什么把戏吗?我正在构建一个json,甚至在页面内对其进行测试,以确保将值分配给正确的范围变量,但当我发送对象时,它接收到null或未定义的变量。请忽略console日志对象中的会话变量,它来自sessionStorage。我在其他控制器中成功地完成了$http.post,但这一个让我感到困惑 控制员: var com = { 'texto' : $scope.texto2, 'cliente' : Session.recallId(), 'rating' : $scop
var com = { 'texto' : $scope.texto2,
'cliente' : Session.recallId(), 'rating' : $scope.rating,
'stockid' : $scope.producto.stockid };
$scope.enviar = function() {
/* texto: cliente: rating: stockid: */
console.log("sending this to alta comentario:");
console.log(com);
$http.post('http://somelink/rest/wsAltaComentario',
(com))
.success(function (data){
console.log("success sending to alta comentario:");
console.log(data);
})
.error(function (data){
console.log("error sending to alta comentario:");
console.log(data);
});
};
我确实得到了控制台错误。
正在传递的对象已记录,如下所示:
客户
null
评级
undefined
斯托克德
"06000001"
texto
这没有意义,因为范围变量确实在视图中得到更新。我实际上是在测试它。以下是表单的视图本身:
<div ng-show="IsVisible">
<div>
<button type="button" class="close" aria-hidden="true">×</button>
<h4 class="modal-title" id="reviewFormModalLabel">Escribir comentario</h4>
</div>
<div>
<form class="nobottommargin" ng-submit="enviar()" id="template-reviewform" name="template-reviewform" novalidate>
<div class="clear"></div>
<div class="col_full col_last">
<label for="template-reviewform-rating">Rating</label>
<select ng-model="rating"
ng-options="r.index as r.value for r in ratings">
<option value="">-- Seleccionar --</option>
</select>
</div>
<div class="clear"></div>
<div class="col_full">
<label for="template-reviewform-comment">Comentario <small>*</small></label>
<textarea ng-model="texto2" class="form-control" id="template-reviewform-comment" name="template-reviewform-comment" rows="6" cols="30" required></textarea>
</div>
<div class="col_full nobottommargin">
<button class="button button-3d nomargin" type="submit" id="template-reviewform-submit" name="template-reviewform-submit" value="submit">ENVIAR</button>
</div>
<pre>Comment is : {{ texto2 | json }} Rating is {{ rating | json }}</pre>
</form>
</div>
<div class="">
<button type="button" ng-hide="cerrar()" class="btn btn-default">Cerrar</button>
</div>
</div>
&时代;
科曼塔里奥描述
评级
--选择的--
科门塔里奥*
羡慕
注释是:{texto2 | json}}评级是{{Rating | json}}
塞拉
很难确切知道这里出了什么问题。你有没有可能组织一个暴徒来演示这个问题?检查“网络”选项卡,看看那里发生了什么。更新模型值时,com
对象中的值不是,因为它们不是引用。简单的解决方案是,将com
作业移动到enviar
方法中。这就解决了问题,谢谢。没有别的办法吗?对变量进行监视?我想这是低效的。我认为在发出POST请求之前立即构建HTTP负载绝对没有问题
<div ng-show="IsVisible">
<div>
<button type="button" class="close" aria-hidden="true">×</button>
<h4 class="modal-title" id="reviewFormModalLabel">Escribir comentario</h4>
</div>
<div>
<form class="nobottommargin" ng-submit="enviar()" id="template-reviewform" name="template-reviewform" novalidate>
<div class="clear"></div>
<div class="col_full col_last">
<label for="template-reviewform-rating">Rating</label>
<select ng-model="rating"
ng-options="r.index as r.value for r in ratings">
<option value="">-- Seleccionar --</option>
</select>
</div>
<div class="clear"></div>
<div class="col_full">
<label for="template-reviewform-comment">Comentario <small>*</small></label>
<textarea ng-model="texto2" class="form-control" id="template-reviewform-comment" name="template-reviewform-comment" rows="6" cols="30" required></textarea>
</div>
<div class="col_full nobottommargin">
<button class="button button-3d nomargin" type="submit" id="template-reviewform-submit" name="template-reviewform-submit" value="submit">ENVIAR</button>
</div>
<pre>Comment is : {{ texto2 | json }} Rating is {{ rating | json }}</pre>
</form>
</div>
<div class="">
<button type="button" ng-hide="cerrar()" class="btn btn-default">Cerrar</button>
</div>
</div>