javascript - href 中的 $scope - AngularJS

标签 javascript jquery angularjs

我有一个如下所示的数组;

$scope.cart = [];

其中包含 ID、名称等项目。

如何将项目包含在 href 中,如下所示;

<a href="http://www.example.co.uk/search-menu/{{$scope.cart.restaurant_id}}/test">

这不起作用。

我还尝试过在购物车中使用ng-repeat=item

仅供引用 当我 console.log($scope.cart) 时,我得到以下内容;

[Object]
0: Object
cookie_id: "j0m3hdkf4c371nueajdi9gf4f3"
date: "0000-00-00"
day: ""
id: "92"
location: ""
restaurant_id: "1"
time: "00:00:00"
user_id: "63"

最佳答案

两种方式数据绑定(bind)的魔力

在 AngularJS 中使用 ng-href 指令

删除 anchor 标记中的$scope。您可以直接访问 View 部分中的范围变量。在 Controller 部分,我们只使用 $scope 对象,不需要 html View 。

<a ng-href="http://example.co.uk/search-menu{{cart[0].restaurant_id}}/test">

关于javascript - href 中的 $scope - AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33895579/

相关文章:

javascript - 未捕获( promise )错误 : Provided weight data has no target variable: block1_conv1_2/kernel

jquery - 灯箱的 CSS 问题

angularjs - 如何动态地创建一个具有特定类的 Angular 的 div?

仅在 Internet Explorer 中中止 ajax 调用时出现 jQuery 错误

javascript - Angular $scope.var 在 Controller 中未定义,但存在于 HTML 中

javascript - 第二个应用程序无法在 Angular JS 中运行

php - 如何将 &lt;/script&gt; 替换为 </scr"+"ipt>

JavaScript 全屏 API

javascript - jquery - 当其他 li 扩展时排序 li 位置

javascript - 在 iPhone 面板的幻灯片中启用内容滚动