【问题标题】:How do I access the properties in the scope of an ng-repeated item inside of an ng-dialog specific to each item?如何访问特定于每个项目的 ng-dialog 内的 ng-repeated 项目范围内的属性?
【发布时间】:2016-09-16 09:14:36
【问题描述】:

所以我有一个 ng-repeated 项目列表,每个项目都有自己的按钮,该按钮调用我使用 ng-dialog 创建的弹出窗口。我需要在每个弹出窗口中打印项目的属性。

html:

<button ng-click="clickToOrder()">order</button>

控制器:

    $scope.clickToOrder = function (dish) {
    var newScope = $scope;
    newScope.dish = dish;
    ngDialog.open({
      template: '{{dish.time}}',
      plain: true,
      scope: newScope
     });
};

所以我通过“菜肴”重复,这些菜肴具有我想在弹出窗口中打印出来的属性“时间”。弹出窗口出现,但与“dish”关联的范围内的属性不会发送到弹出窗口。有什么方法可以将 ng-repeat 中每道菜的特定属性发送到 ng-dialog 弹出窗口?

【问题讨论】:

  • 您没有将dish 传递给函数。它应该是ng-click="clickToOrder(dish)" 或类似的东西。此外,var newScope = $scope 看起来很奇怪,并且可能与您期望的不太一样;我不知道这是 nDialog 语法的一部分还是什么,但这绝对是一个泄漏的抽象。
  • ^救世主!那就是我忘了在html中传递菜

标签: angularjs angularjs-scope angularjs-ng-repeat ng-dialog


【解决方案1】:

你可以这样做:

ngDialog.open({
    controller: function Ctrl(dep) {/*...*/},
    resolve: {
        dish: function getDish() {
            return dish;
        }
    }
});

send variables to controller('resolve') in ngDialog

【讨论】:

    猜你喜欢
    • 2013-01-17
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    • 2016-11-28
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多