Destroy transclude scopes
gitea/salix/1625-worker_department_treeview This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-10-04 12:20:49 +02:00
parent 8e80f53d30
commit 366d1123d4
3 changed files with 10 additions and 28 deletions

View File

@ -3,7 +3,7 @@
<li ng-repeat="item in $ctrl.items" >
<div
ng-class="{expanded: item.active}"
ng-click="$ctrl.toggle($event, item)"
ng-click="$ctrl.onClick($event, item)"
class="node clickable">
<vn-icon
class="arrow"

View File

@ -2,40 +2,16 @@ import ngModule from '../../module';
import Component from '../../lib/component';
class Controller extends Component {
constructor($element, $scope, $transclude) {
super($element, $scope);
this.$transclude = $transclude;
}
toggle(event, item) {
onClick(event, item) {
if (event.defaultPrevented || !item.sons) return;
event.preventDefault();
this.treeview.onToggle(item);
}
select(item, value) {
this.treeview.onSelection(item, value);
}
onIconClick(icon, item, parent, index) {
let parentController = this.parentScope.$ctrl;
icon.callback.call(parentController, item, parent, index);
}
onCreate(parent) {
this.treeview.onCreate(parent);
}
onDrop(item, dragged, dropped) {
this.treeview.onDrop(item, dragged, dropped);
}
get isInsertable() {
return Array.isArray(this.parent) || this.parent.childs;
}
}
Controller.$inject = ['$element', '$scope', '$transclude'];
ngModule.component('vnTreeviewChilds', {
template: require('./childs.html'),

View File

@ -6,11 +6,17 @@ class Controller {
}
$onInit() {
this.treeview.$transclude((tClone, $scope) => {
this.treeview.$transclude(($clone, $scope) => {
this.$contentScope = $scope;
$scope.item = this.item;
this.$element.append(tClone);
this.$element.append($clone);
});
}
$onDestroy() {
if (this.$contentScope)
this.$contentScope.$destroy();
}
}
Controller.$inject = ['$element'];