In jQuery, i was able to to something like the following:
在jQuery中,我可以这样做:
$('a[rel=external]').attr('target', '_blank');
This would make all the [rel=external] urls open in a new window/tab. How can I do the same in Angular?
这将使所有[rel=外部]url在新的窗口/选项卡中打开。我怎么用角来做同样的事?
1 个解决方案
#1
2
You can do it in vanilla JavaScript, if you don't want to use jQuery
如果您不想使用jQuery,那么您可以在JavaScript中使用它。
[].forEach.call(document.querySelectorAll('a[rel=external]')
, function(elem){
elem.setAttribute('target','_blank')
});
Or you can use the angular.element as the jQuery function, more on that in the docs
或者你可以用角。元素作为jQuery函数,在文档中更详细。
angular.element('a[rel=external]').attr('target', '_blank');
angular.element(“[rel =外部]”)。attr(“目标”,“平等”);
#1
2
You can do it in vanilla JavaScript, if you don't want to use jQuery
如果您不想使用jQuery,那么您可以在JavaScript中使用它。
[].forEach.call(document.querySelectorAll('a[rel=external]')
, function(elem){
elem.setAttribute('target','_blank')
});
Or you can use the angular.element as the jQuery function, more on that in the docs
或者你可以用角。元素作为jQuery函数,在文档中更详细。
angular.element('a[rel=external]').attr('target', '_blank');
angular.element(“[rel =外部]”)。attr(“目标”,“平等”);