angularjs $ state.go在表内不起作用

时间:2018-11-03 19:11:54

标签: javascript angularjs angular-ui-router

我在一个表中有一个项目列表,我想使用$ state.go()导航到某些项目的详细信息。

  

我尝试了几种解决方案,包括ui-sref =“ state-name”。 ng-click功能...,但这些方法均无效。

最后,我在stackoverflow中找到了另一种方法。但是问题仍然存在。

这就是我写的代码。

app.run(function ($rootScope, $state) {

  $rootScope.navigate = function ($event, to, params) {
    console.log(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);
    }
  }
});


 <a ng-click="navigate($event,'vehicle.Detail', {id:'@item.Id'})">@Html.DisplayFor(modelItem => item.VehicleName)</a>
  

这是我的状态:

.state('vehicle.Detail',
        {
            url: 'Detail',
            templateUrl: '../Administrator/Vehicle/Detail/:id',

        })

0 个答案:

没有答案