Javascript 角度1/ng,如果仅在某个条件下进行一次性绑定
在我的模板中,我有:Javascript 角度1/ng,如果仅在某个条件下进行一次性绑定,javascript,angularjs,ui-select,angular-ui-select,angularjs-ng-if,Javascript,Angularjs,Ui Select,Angular Ui Select,Angularjs Ng If,在我的模板中,我有: <div ng-if="$ctrl.show()"> <input class="form-control" type="text"> </div> 我只希望在通过select=“$ctrl.show()”)上的属性单击选择输入(ui select)时处理该函数: {{$select.selected.label} 此情况可能类似于以下示例情况:仅当单击一个ng click时启动该函数将您的ng show更改为一个变量,并保持按
<div ng-if="$ctrl.show()">
<input class="form-control" type="text">
</div>
我只希望在通过select=“$ctrl.show()”)上的属性单击选择输入(ui select)时处理该函数:
{{$select.selected.label}
此情况可能类似于以下示例情况:仅当单击一个
ng click时启动该函数将您的ng show更改为一个变量,并保持按原样选择=“$ctrl.show()”
在你看来:
<div ng-if="$ctrl.shouldShow">
<input class="form-control" type="text">
</div>
最好不要在ng if、ng show和ng hide中使用函数,因为这是一项性能测试Angular不会不断计算变量$ctrl。shouldShow
?抱歉,在摘要周期中,它会,但计算函数显然比布尔值要花更多的时间,将其设置为布尔值可以提供所需的功能,因此,如果我理解的话,它可以归结为相同的,Angular一直在寻找$ctrl.shouldShow
(如果存在或不存在)。到底有什么不同?阅读angularjs摘要周期有助于进一步理解差异。
<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>
<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')
}
}