0

在我的模板中,我有:

<div ng-if="$ctrl.show()">
  <input class="form-control" type="text">
</div>

在我的组件中

  show() {
    if (angular.isDefined(this.parking.parkingType)) {
      return this.parking.parkingType.labelKey === 'parking_type.air'
    }
  }

我希望仅在单击属性的选择输入(ui-select)时才处理函数on-select="$ctrl.show()"

 <ui-select ng-model="$ctrl.parking.parkingType"
             on-select="$ctrl.show()">
    <ui-select-match allow-clear="true">
        <span>{{ $select.selected.label }}</span>
    </ui-select-match>
    <ui-select-choices repeat="item in $ctrl.parkingType | filter: { label: $select.search }">
        <span ng-bind-html="item.label"></span>
    </ui-select-choices>
  </ui-select>

此案例可能类似于以下示例案例:仅在单击ng-click

4

1 回答 1

1

将您的 ng-show 更改为变量并保持on-select="$ctrl.show()"原样

在您看来:

<div ng-if="$ctrl.shouldShow">
  <input class="form-control" type="text">
</div>

在您的组件中:

$ctrl.show = function() {
  if (angular.isDefined(this.parking.parkingType)) {
    $ctrl.shouldShow = (this.parking.parkingType.labelKey === 'parking_type.air')
  }
}

最好不要在 ng-if、ng-show 和 ng-hide 中使用函数,因为它会影响性能

于 2017-07-25T15:01:25.570 回答