Is there anyway to listen for an event after the $watch function gets completed and the html is rendered?
scope.$watch('treeData', on_treeData_change, true);
on_treeData_change = function() {
var add_branch_to_list, root_branch, _i, _len, _ref, _results;
for_each_branch(function(b, level) {
if (!b.uid) {
return b.uid = "" + Math.random();
}
});
for_each_branch(function(b) {
var child, _i, _len, _ref, _results;
if (angular.isArray(b.children)) {
_ref = b.children;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
_results.push(child.parent_uid = b.uid);
}
return _results;
}
});
scope.tree_rows = [];
for_each_branch(function(branch) {
var child, f;
if (branch.children) {
if (branch.children.length > 0) {
f = function(e) {
if (typeof e === 'string') {
return {
label: e,
children: []
};
} else {
return e;
}
};
return branch.children = (function() {
var _i, _len, _ref, _results;
_ref = branch.children;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
_results.push(f(child));
}
return _results;
})();
}
} else {
return branch.children = [];
}
});
add_branch_to_list = function(level, branch, visible) {
var child, child_visible, tree_icon, _i, _len, _ref, _results;
if (branch.expanded == null) {
branch.expanded = false;
}
if (!branch.children || branch.children.length === 0) {
tree_icon = attrs.iconLeaf;
} else {
if (branch.expanded) {
tree_icon = attrs.iconCollapse;
} else {
tree_icon = attrs.iconExpand;
}
}
branch.level = level;
scope.tree_rows.push({
level: level,
branch: branch,
label: branch[expandingProperty],
tree_icon: tree_icon,
visible: visible
});
if (branch.children != null) {
_ref = branch.children;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
child_visible = visible && branch.expanded;
_results.push(add_branch_to_list(level + 1, child, child_visible));
}
return _results;
}
};
_ref = scope.treeData;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
root_branch = _ref[_i];
_results.push(add_branch_to_list(1, root_branch, true));
}
return _results;
};
Here I want a method to be executed after the on_tree_data_change gets executed and the html is rendered.
It still returns null, even, i call document.getElementById("....") at the end of the watch listener. I have a chcekbox for each branch in a tree and the Requirement is to check all the branches in a tree when the parent branch checkbox is checked. But when the tree is collapsed, document.getElementById returns null for the checkbox. So, on expanding the tree, this $watch gets called and thought of calling the getElementById ... for all the checke boxes after the $watch gets completed and after the dom is rendered.
Thanks, Baskar.S