角度 1/ ng-if 仅在一个条件下一次性绑定



在我的模板中,我有:

<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'
}
}

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

<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时启动函数

将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中使用函数,因为它会影响性能。

最新更新