在spring mvc web app项目中使用表单动作链接中的angularjs数据时出错
我正在使用angularjs检索SpringWeb应用程序项目中的数据。它能够检索和显示我使用{{}传递的所有位置的数据,但在我的表单操作链接中,它无法读取传递的值。语法有什么问题在spring mvc web app项目中使用表单动作链接中的angularjs数据时出错,angularjs,spring-mvc,Angularjs,Spring Mvc,我正在使用angularjs检索SpringWeb应用程序项目中的数据。它能够检索和显示我使用{{}传递的所有位置的数据,但在我的表单操作链接中,它无法读取传递的值。语法有什么问题 <div class="container text-center" ng-app="myApp" ng-controller="myCtrl"> <div ng-repeat="product in Data" > <div class=col-lg-
<div class="container text-center" ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="product in Data" >
<div class=col-lg-5>
<center>
<img src="<c:url value='/resource/image/{{product.name}}.jpg'/>" />
</center>
</div>
<div class=col-lg-7>
<table class="table table-striped">
<tr>
<h1>{{product.name}}</h1>
</tr>
<tr>
<th>Description</th>
<td>{{product.description}}</td>
</tr>
<tr>
<th>Category</th>
<td>{{product.category}}</td>
</tr>
<tr>
<th>Price</th>
<td>Rs.{{product.price}}</td>
</tr>
^
till here it displays the data using angular js
</table>
</div>
<form:form method="POST" modelAttribute="cart" action="${pageContext.request.contextPath}/user/addtocart?productId={{product.id}}">
^
here it doesnt read the data passed using angularjs
<sec:authorize access="hasRole('ROLE_USER')">
<input type="submit" class="btn btn-info btn-lg" value="Add to Cart" />
</sec:authorize>
</form:form>
" />
{{product.name}
描述
{{product.description}}
类别
{{product.category}
价格
卢比{{产品价格}
^
在此之前,它使用angular js显示数据
^
这里它不读取使用angularjs传递的数据
将HTML更改为下面的方式,因为您的ng控制器
标记在窗体之前结束,因为角度范围限制为
标记本身,因此不会计算您的{}
表达式
<div class="container text-center" ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="product in Data">
<div class=col-lg-5>
<center>
<img src="<c:url value='/resource/image/{{product.name}}.jpg'/>" />
</center>
</div>
<div class=col-lg-7>
<table class="table table-striped">
<tr>
<h1>{{product.name}}</h1>
</tr>
<tr>
<th>Description</th>
<td>{{product.description}}</td>
</tr>
<tr>
<th>Category</th>
<td>{{product.category}}</td>
</tr>
<tr>
<th>Price</th>
<td>Rs.{{product.price}}</td>
</tr>
</table>
<form:form method="POST" modelAttribute="cart" action="${pageContext.request.contextPath}/user/addtocart?productId={{product.id}}">
<sec:authorize access="hasRole('ROLE_USER')">
<input type="submit" class="btn btn-info btn-lg" value="Add to Cart" />
</sec:authorize>
</form:form>
</div>
</div>
</div>
" />
{{product.name}
描述
{{product.description}}
类别
{{product.category}
价格
卢比{{产品价格}
将HTML更改为下面的方式,因为您的ng控制器
标记在窗体之前结束,因为角度范围限制为
标记本身,因此不会计算您的{}
表达式
<div class="container text-center" ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="product in Data">
<div class=col-lg-5>
<center>
<img src="<c:url value='/resource/image/{{product.name}}.jpg'/>" />
</center>
</div>
<div class=col-lg-7>
<table class="table table-striped">
<tr>
<h1>{{product.name}}</h1>
</tr>
<tr>
<th>Description</th>
<td>{{product.description}}</td>
</tr>
<tr>
<th>Category</th>
<td>{{product.category}}</td>
</tr>
<tr>
<th>Price</th>
<td>Rs.{{product.price}}</td>
</tr>
</table>
<form:form method="POST" modelAttribute="cart" action="${pageContext.request.contextPath}/user/addtocart?productId={{product.id}}">
<sec:authorize access="hasRole('ROLE_USER')">
<input type="submit" class="btn btn-info btn-lg" value="Add to Cart" />
</sec:authorize>
</form:form>
</div>
</div>
</div>
" />
{{product.name}
描述
{{product.description}}
类别
{{product.category}
价格
卢比{{产品价格}
您的HTMLY标签上有两个缺少关闭的div
标记。您的HTMLY标签上有两个缺少关闭的div
标记。您的HTMLY标签上有两个缺少关闭的div
标记。是的!更新了我的答案。谢谢你:)是的,我知道最后两个div需要在结尾处关闭。但是我在表单之前关闭了,而不是ng repeat或ng controllerInvalid HTML标记的开始或结束,这会导致Angular的意外行为,因为它尝试评估DOM,在您的情况下,它会将您的结束标记作为ng repeat end标记。如果我在表单标签用于显示product.id,它显示。因此我认为angular正在向那里传递数据。您需要为
和
@PrinceG添加两个关闭div
标签。是的,您是对的!更新了我的答案。。谢谢:)是的,我知道最后两个需要关闭的div。但是我在表单之前关闭了,而不是ng重复或ng controllerInvalid HTML标记的开始或结束导致Angular出现意外行为,因为它尝试评估DOM。在您的案例中,它将您的结束标记作为ng repeat end标记。如果我在表单标记中添加另一个标记以显示product.id,它将显示。因此我认为Angular正在那里传递数据