【问题标题】:AngularJS ng-repeat does not update the $ctrl in UIAngularJS ng-repeat 不会更新 UI 中的 $ctrl
【发布时间】:2023-03-17 16:14:01
【问题描述】:

我正在使用 applyType 方法更新我的模型,但这些项目没有反映在 UI 中。

这就是我正在做的事情

我的模型是:model.js

export default function model(
  $scope,
) {

...

model.$name = 'editModelController';
model.$templateUrl = {
  sku: templateUrl,
};

我的组件:

index.js

export default function addItemDialog(app) {
  app.component('addItemDialog', {
    controller,
    bindings: {
      resource: '<',
      ngIf: '=',
    },
  });
}

addItemDialog.js

export default function addItem(
  $q,
  $mdDialog,
) {
  this.$onInit = () => {
    ...
    this.applyType();
  };
}

this.applyType = () => {
    this.units = this.loadMoreUnits();
};

addItem.$inject = [
  '$q',
  '$mdDialog',
];

addItemDialog.pug

md-select.select(
    ng-model="$ctrl.unit",
    placeholder="Unit",
    name="unit",
)
    md-option.select__option(
      ng-repeat="unit in $ctrl.units",
      value="{{ unit.unit }}",
    )
      .select__option-content
        span.select__option-text {{ unit.description }}

我正在控制台记录 this.units 它在那里更新但未在 UI 中更新。

【问题讨论】:

    标签: angularjs pug


    【解决方案1】:

    回答,因为我没有足够的代表发表评论。

    您是否尝试过像这样访问单位对象: unit in units 而不是使用$ctrl

    我见过一些情况,您可以直接从控制器访问字段,而无需显式引用控制器。

    问候,

    M

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 2015-08-08
      相关资源
      最近更新 更多