如何在Angular UI树上调用crashAll函数? [英] How to call collapseAll function on Angular UI tree?
问题描述
我正在使用 angular-ui-tree 指令在我的计算机上显示一棵树AngularJS应用程序.但是,我现在想倒塌的树.文档指出作用域上有一个名为collapseAll
的函数,但未显示如何调用此函数的示例.
I am using the angular-ui-tree directive to show a tree in my AngularJS application. However, I would now like to collapse the tree. The documenation states that there is a function called collapseAll
on the scope, but doesn't show an example of how to call this.
搜索Google提出了此问题,其中有人要求确切同样的事情-不幸的是,链接的答案导致404.
Searching Google has brought up this issue where someone asks for exactly the same thing - unfortunately the linked answer results in a 404.
我没有得到的是:如果可以通过ui-tree
指令的范围访问此函数,但是此指令使用其自己的隔离范围,则有效访问该函数意味着访问该指令的范围.我如何到达那个范围?
What I don't get is: If this function is accessible via the scope of the ui-tree
directive, but this directive uses its own isolated scope, accessing the function effectively means accessing the directive's scope. How do I get to that scope?
我知道如何从上面要求一个控制器(在指令中使用^
语法),但是如何访问下面的作用域?
I know how to require a controller from above (using the ^
syntax in a directive), but how do I access a scope below?
推荐答案
由div ng-controller ="BasicExampleCtrl"
in basic-example.html
wrap by div ng-controller="BasicExampleCtrl"
<div class="row">
<div class="col-sm-12">
<h3>Basic Example</h3>
<button ng-click="expandAll()">Expand all</button>
<button ng-click="collapseAll()">Collapse all</button>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div ui-tree id="tree-root">
<ol ui-tree-nodes ng-model="data">
<li ng-repeat="node in data" ui-tree-node ng-include="'nodes_renderer.html'"></li>
</ol>
</div>
</div>
</div>
在basic-example.js中
in basic-example.js
angular.module('demoApp')
.controller('BasicExampleCtrl', ['$scope', function ($scope) {
...
$scope.collapseAll = function () {
$scope.$broadcast('angular-ui-tree:collapse-all');
};
$scope.expandAll = function () {
$scope.$broadcast('angular-ui-tree:expand-all');
};
...
}]);
这篇关于如何在Angular UI树上调用crashAll函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!