- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在开发一个购物车项目。
它有不同的类别。
每个类别都有不同的产品。
当我将特定类别的产品添加到购物车时,它就会被添加。
当我返回并将另一个产品添加到同一类别的购物车时,它已正确添加,并且前一个产品也显示良好。
但是,当转到另一个类别并将产品添加到购物车时,购物车页面会清除所有以前的产品,并且不会显示任何以前的产品。
如何解决此问题并维护添加到购物车中但未在整个项目中清除的产品。
我没有使用任何服务来维护它,我只想在 angularjs 中维护它
最佳答案
只有两种方法可以在 Angular 摘要周期内的所有 Angular 应用程序中保存数据。
1--$rootScope(not recommended)
2--using Angular Services
因为你的评论我在推断你说“我没有使用任何服务来维护它,我只想在 angularjs 中维护它”您正在引用第三方或后端服务。 Angular 有自己的一套服务,您也可以使用,即 cookie 服务、存储服务,或者您可以推出自己的运输车服务(这就是建议),构建您的购物卡服务来处理您的所有操作并跟踪您的数据。 Angular 服务是应用程序的单例对象,允许它们保存数据。创建服务非常简单,您可以这么说
app.service('myservice',['$rootScope','$http','$timeout',function($rootScope,$http,$timeout){
//$rootscope useful if you want to broadcast events to the app
//$http useful if you want to update based on the users selection or deletion
//$timeout useful if you want to set time based alerts or expirations
var storage={};
return{
insert:function(item){/*logic to insert an item into storage*/},
remove:function(id){/*logic to remove an item from storage*/},
get:function(id){/*logic to get all items*/}
}
}])
app.Controller('Category1ItemsController',['myservice',function(myservice){
$scope.items=[1,2,3,4,5,6]
$scope.appendItem=function(item){
myservice.insert(item);
}
}]);
<ul ng-controller="Category1ItemsController">
<li ng-repeat="item in items">
{{item}}
<button ng-click="appendItem(item)">Add</button>
</li>
</ul>
这样的事情可能会让你更清楚。您使用什么生成器/模板项目?
关于javascript - 当我们切换到 Angular js中的其他 View 时如何获取购物车值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24073983/
我们都在流行的网站上看到,购物车图标的右上角有一个小图标!我必须在我的 ASP .NET 网页中使用类似的东西。 如何让这个图标位于购物车图标的右上角.. 购物车的图标是一个普通的 bootstrap
Closed. This question does not meet Stack Overflow guidelines 。它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 Stack Ov
可以使用 REST 架构约束来实现购物车吗? 我想把我的问题集中在 session 状态上。在实现购物车的典型 MVC 应用程序中,很可能 session 对象将在 session 中管理,购物车作为
我的网上商店使用自己的模板,但在我的网站上我使用货币欧元而不是美元。哪里可以编辑啊。 http://i50.tinypic.com/67rvhc.png 最佳答案 进入系统>配置。 然后在“通用”>“
我想在我的门户中使用购物车。我可以获得 jquery 的购物车插件吗? 格纳尼亚尔·祖贝尔 最佳答案 http://simplecartjs.com/不是 JQuery,但如果 PayPal 或 Go
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
我正在尝试将产品添加到我的购物车。 我收到一条错误消息: 警告:为 foreach() 提供的参数无效 它告诉我以下代码出现错误: function isInCart($id) { if (!empt
我目前正在使用 PHP 开发购物车,我正在尝试弄清楚如何使用我编写的代码将商品添加到购物车本身。我的数据库中的项目显示正确,但只有 $item 下的最后一个数组被添加到购物车。以下显示项目。 $res
在我的laravel购物车上,我创建了一个delete函数,使用json或dd函数进行测试时似乎还可以,但是尝试返回路线购物车 View Route [cart] not defined.时,这是一个
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
将相同的产品添加到购物车时,它正在添加新行,但如果相同的产品 ID 已在购物车中,则需要更新数量。 我需要它与数量更新保持一致。 最佳答案 您需要覆盖 app/code/core/Mage/Sales
你好, 我正在创建一个用于培训目的的 PHP 商店。我希望用户能够查看他最后下的订单 - 但我很难意识到这一点。 我的数据库中有这些表: 客户( child 、姓名、地址...) 产品(pid、pro
我正在考虑建立一个迷你购物网站。不涉及支付方式,只是显示和维护的所选产品的总数。这将由商店中的一个人操作以进行和监控销售。 概念是:产品应该在页面中显示为大图像,通过点击它们我将它们存储在购物车中。然
我有以下产品和购物车表格: //产品表 Products: id | Product_value ----------------------- 1 | Product
我尝试使用 php ang mysql 在 google 中搜索购物车中的代码。当我单击“添加到购物车”按钮时,我的 cart.php 中没有显示任何内容。请帮助我。 这是我的产品.php ">ADD
我正在为摄影业务创建 PHP 购物车。这是我尝试的第一个电子商务网站(新手) 我已成功将产品添加到购物车(存储在 session 中)(产品:打印品、 key 圈、磁铁等) 但是我还需要将 image
变量被添加到从另一个页面传递的 session 数组 此处为详细信息页面 string(4) "3911" [1]=> string(4) "5005" [2]=> NULL [3]=> strin
我的模型中设置了以下核心数据关系。 类别 -> 产品 -> 购物车产品 1)) { // handle error } else if (![cartProducts count]) {
我已经根据示例实现了jQuery的购物卡:http://jsfiddle.net/RR6z5/1/ 但是有一个小错误。当我将一个元素从产品拖到购物卡,然后无拖放,我从购物卡拖到产品时,产品中的原始元素
大家好,就 css 和 javascript 而言,我是个新手。我正在使用的新主题是让我的 paypal minicart 显示在内容下方,因此您不能单击它,也不能从中删除内容,但您可以看到购物车稍微
我是一名优秀的程序员,十分优秀!