我有一个如下所示的数组;
$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/