[英]AngularJS: how to initiate a ng-click on load
We have a widget in ServiceNow where we have buttons that show pre-configured filters.我们在 ServiceNow 中有一个小部件,其中有显示预配置过滤器的按钮。 The buttons work great onClick, but we would like the first button to be clicked and the first filter to be applied on load.
这些按钮在点击时效果很好,但我们希望第一个按钮被点击,第一个过滤器在加载时应用。 Is there a way to initiate this on load?
有没有办法在加载时启动它? We tried using ng-init, but we couldn't get that to work.
我们尝试使用 ng-init,但我们无法让它工作。
<p><strong>Filters:</strong></p>
<button ng-if="options.show_preconfigured_filters=='true'"
class="btn btn-outline-primary pull-left m-r-sm m-b-sm"
ng-repeat="filters in data.preconfigured_filters | orderBy : 'order' track by $index"
ng-click="c.applyFilter(filters);">
<i class="glyphicon glyphicon-filter m-r-sm"></i>{
{filters.title}}
</button>
<div class="clearfix"></div>
c.applyFilter = function(filter) {
$scope.data.filter = filter.filter;
c.appendQuery($scope.data.filter);
}
One approach is to compute the ordered list in the controller:一种方法是在控制器中计算有序列表:
var orderedList = $filter('orderBy')($scope.data.preconfigured_filters, 'order');
c.applyFilter(orderedList[0]);
This executes the same function that a user invokes by clicking the first item.这将执行用户通过单击第一项调用的相同功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.