angular.module('app').directive('focus', function ($timeout,$parse) {
  return {
    restrict: 'A',
    link: function ($scope, $ele, $attrs, $controller) {
      let model = $parse($attrs.focus);
      let unBind=  $scope.$watch(model, function (newValue,oldValue) {
        if (newValue === true) {
          $timeout(function () {
            $ele[0].focus();
          });
        }
      });
      $ele.bind('blur', function () {
        $scope.$apply(model.assign($scope, false));
      });
      $scope.$on("destroy", () => {
        unBind();
      })
    }
  }
});

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-14
  • 2021-05-15
  • 2022-12-23
  • 2021-09-08
  • 2022-03-02
相关资源
相似解决方案