Javascript 如何将scrollIntoView移动到angular指令中
请参阅我的代码片段: 指令Javascript 如何将scrollIntoView移动到angular指令中,javascript,angularjs,Javascript,Angularjs,请参阅我的代码片段: 指令节点: myModule.directive ('node', ['$compile', function ($compile) { return { restrict: 'A', link: function (scope, element, attrs) { var node = scope.node; node.scrollTarget = element; // ... } }); 功能滚
节点
:
myModule.directive ('node', ['$compile', function ($compile) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var node = scope.node;
node.scrollTarget = element;
// ...
}
});
功能滚动
$scope.scroll = function (node) {
$scope.showTree (node);
$timeout (function () {
node.scrollTarget[0].scrollIntoView ();
}, 0, false);
};
根据ng click=scroll(node)
调用scroll
,并更改模型(showTree
),以及执行一些dom操作(scrollIntoView
)。
据说在控制器中应该避免dom操作。我怎样才能写得更好