要在新标签页中打开ui-sref链接,您可以使用AngularJS的ui-router模块的state.go函数,并将第三个参数设置为{target: '_blank'}。以下是一个示例:
HTML代码:
Open in New Tab
JavaScript代码:
app.controller('MainController', function($scope, $state, $window) {
$scope.openInNewTab = function() {
var url = $state.href('stateName', {}, {absolute: true});
$window.open(url, '_blank');
};
});
在上面的示例中,当用户点击"Open in New Tab"链接时,会调用openInNewTab函数。该函数使用$state.href函数获取到指定状态(stateName)的URL,并使用$window.open函数在新标签页中打开该URL。确保将stateName替换为您的实际状态名称。
请注意,上述示例假设您已将ui.router模块添加到您的AngularJS应用程序中,并且已正确配置了状态和路由。