AngularJS ng-repeat md-focus最后一个元素?

时间:2018-07-15 08:19:01

标签: javascript angularjs css3 angular-material

<div ng-repeat="item in items track by $index" md-autofocus="$last">
<div>
 {{item}
</div>
<div>

上面的代码在md对话框中,该对话框具有垂直滚动。

要求是在运行时添加项目时滚动到最后一个元素。

1 个答案:

答案 0 :(得分:0)

您应该自己编写指令来执行此操作,下面是一个可能可以帮助您完成此操作的示例;

基本上,当添加新项目时,$ anchorScroll服务将用于滚动到该特定元素。

app.directive('scrollToLast', ['$location', '$anchorScroll', function($location, $anchorScroll){

  function linkFn(scope, element, attrs){
      $location.hash(attrs.scrollToLast);
      $anchorScroll();
  }

  return {
    restrict: 'AE',
    scope: {

    },
    link: linkFn
  };

}]);

DEMO

相关问题