我有重复的表格行和一个 ui-sref
在他们身上设置的属性。单击时,它们会导航到正确的位置。但是,它们不能通过 ⌘ 命令 单击(或在新选项卡中打开)。
我假设这是因为他们设置了 href
当元素是 anchor 标记 ( <a>
) 时,它会被接受,但在其他元素上则不会。
<tr ng-repeat="item in items" ui-sref="view-item({itemId:item.id})">
有什么快速修复的想法吗?
最佳答案
我能够通过 ng-click
函数完成我想要的。
app.run(function($rootScope, $state) {
$rootScope.navigate = function($event, to, params) {
// If the command key is down, open the URL in a new tab
if ($event.metaKey) {
var url = $state.href(to, params, {absolute: true});
window.open(url,'_blank');
} else {
$state.go(to, params);
}
};
});
用法
<tr ng-repeat="item in items" ng-click="navigate($event, 'view-item',{itemId:item.id})">
关于javascript - tr 元素上的 ui-sref 不会在新选项卡中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28872720/