javascript - Angular 1/ ng-if one-time binding only in a condition -
in template have :
<div ng-if="$ctrl.show()"> <input class="form-control" type="text"> </div>
in component
show() { if (angular.isdefined(this.parking.parkingtype)) { return this.parking.parkingtype.labelkey === 'parking_type.air' } }
i want angular process function when clicking on select input (ui-select) attribute 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>
this case may similar sample case of: launching function when clicking on ng-click
change ng-show variable , keep on-select="$ctrl.show()"
is
in view:
<div ng-if="$ctrl.shouldshow"> <input class="form-control" type="text"> </div>
in component:
$ctrl.show = function() { if (angular.isdefined(this.parking.parkingtype)) { $ctrl.shouldshow = (this.parking.parkingtype.labelkey === 'parking_type.air') } }
it's practice not have function in ng-if, ng-show, , ng-hide because it's performance hit
Comments
Post a Comment