Angularjs:没有将ui-sref传递给路线

时间:2015-05-21 12:41:00

标签: angularjs angular-ui-router

如果我插入一个值它可以工作,但我的表单没有将for参数传递给我的路由脚本。以下是表格摘录:

$stateParam

然后这是路线的部分:

<tr ng-repeat="folder in vm.folders" ng-click="editRecord(folder)">
     <td >{{folder.subfolderId}}</td>
     <td >
         <a ui-sref="subfolderDetail({id: folder.subfolderId})">{{folder.displayName}}
         </a></td>
     <td>{{folder.description}}</td>
     <td>{{folder.subfolderGuid}}</td>
</tr>

function config($stateProvider) { $stateProvider .state('subfolders', { url: "/subfolders", templateUrl: "app/subfolders/subfolders.html", controller: "subfolderListController as vm" }) .state('subfolderDetail', { url: "/subfolderDetail", templateUrl: "app/subfolders/subfolderDetail.html", controller: "subfolderDetailController as vm", resolve: { subfolderResource: "subfolderResource", subfolder: function (subfolderResource, $stateParams) { var vid = $stateParams.id; //alert($stateParams); //var vid = 9; return subfolderResource.get({ id: vid }).$promise; } } }) .state('/optinoptions', { templateUrl: '/app/optinOptions/optinOptions.html' }); //$locationProvider.html5Mode(true); } config.$inject = ['$stateProvider']; 的路由未获得'subfolderDetail'变量。如果我设置了一个变量(已注释掉),它会正确调用WebApi。我错过了什么?

1 个答案:

答案 0 :(得分:1)

您似乎忘记声明 参数:

 .state('subfolderDetail', {
    url: "/subfolderDetail/:id",

这样我们就说:state&#39; subfolderDetail&#39;有网址参数 id ,在&#34; / subfolderDetail /&#34;之后会在网址中出现。

还有其他方式(例如 params: {} ,但这是最常见的标准。在这里阅读更多内容:

$stateProvider