我有什么诡计吗?我正在构建一个json,甚至在页面内测试它以确保将值分配给正确的范围变量,但是当我发送对象时它接收到null或未定义的变量。请忽略控制台日志对象中的会话变量,它来自sessionStorage。我成功地在其他控制器中完成了$ http.post,但这个让我感到困惑。
控制器:
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);
});
};
我确实收到了控制台错误。 记录传递的对象,如下所示:
cliente
null
的评价
undefined
stockid
"06000001"
texto
undefined
没有意义,因为范围变量DO在视图中得到更新。我实际测试它。以下是表单的视图:
<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>