Open links in new window using AngularJS

后端 未结 7 1218
时光说笑
时光说笑 2020-11-27 04:17

Is there a way to tell AngularJS that I want links to be opened in new windows when the user clicks on them?

With jQuery I would do this:

jQuery(\"a.         


        
7条回答
  •  轮回少年
    2020-11-27 04:49

    @m59 Directives will work for ng-bind-html you just need to wait for $viewContentLoaded to finish

    app.directive('targetBlank', function($timeout) {
      return function($scope, element) {
        $scope.initializeTarget = function() {
          return $scope.$on('$viewContentLoaded', $timeout(function() {
            var elems;
            elems = element.prop('tagName') === 'A' ? element : element.find('a');
            elems.attr('target', '_blank');
          }));
        };
        return $scope.initializeTarget();
    
      };
    });
    

提交回复
热议问题