目前我正在使用 angular 1.6 应用程序 我从堆栈溢出实现了此代码,但这并不能解决我的解决方案。
这是我下面的代码
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);
}
};
});
我的网页代码
<div class="title" data-ng-click="$ctrl.goToDetails($event)" data-ng-bind="$ctrl.config.entryTitle"></div>
控制器
$state.go('entry-details', { entryId: vm.config.id, query: vm.query });
我是角度的新手,所以请建议如何实现。如果我得到一个小提琴会更好。
代码中所需要的只是: absolute: false
并调用function navigate with ng-click
,下面是经过测试的示例。 它工作正常:
app.run(function($rootScope, $state,$window) {
$rootScope.navigate = function($event, to, params) {
// If the command key is down, open the URL in a new tab
if ($event.ctrlKey) {
var url = $state.href(to, params, {absolute: false});
$window.open(url,'_blank');
} else {
$state.go(to, params);
}
};
})
<div ng-click="navigate($event, 'StateName', {PARAMS:PARAMS})">ClickMe</div>