gpt4 book ai didi

javascript - Angular UI-Router 无法从其父状态解析子状态(使用动态 URL 参数)

转载 作者:行者123 更新时间:2023-11-30 17:28:24 24 4
gpt4 key购买 nike

我有一个包含数据的父状态,我想将其用于创建具有动态 URL 参数的子状态。目前,我收到此错误,“错误:无法从状态‘dash/authors’解析‘authors/view/Baxter Richard’”。

在我的 router.js 文件中:

      .state('dashboard', {
url: "/auth/dashboard",
templateUrl: 'angular/dashboard.html',
controller: 'DashboardController',
resolve: {
user : function(UserService) {
return UserService.get();
},
user_drive : function(UserDriveService) {
return UserDriveService.get();
}
}
})

.state('dash/authors', {
parent: 'dashboard',
url: "/authors",
templateUrl: 'angular/partials/dash.authors.html'
})

.state('authors/create', {
parent: 'dash/authors',
url: "/create",
templateUrl: 'angular/partials/dash.authors.create.html'
})

.state('authors/view', {
parent: 'dash/authors',
url: "/:title",
templateUrl: 'angular/partials/dash.author-view.html'
})

.state('dash/epubs', {
parent: 'dashboard',
url: "/epubs",
templateUrl: 'angular/partials/dash.epubs.html'
});

$urlRouterProvider.otherwise('/');
$locationProvider.html5Mode(true).hashPrefix('!');

在我的 dashboard_controller.js 文件中:

    angular.module("app").controller("DashboardController", function($scope, $location, $http, user, user_drive) {

$scope.user = user.data;
$scope.user_drive = user_drive.data;

});

在我的 dash.authors.html 部分:

          <div class="col-sm-3" ng-repeat="author in user_drive.authors | orderBy:'title'">
<a ui-sref="authors/{{author.title}}">
<div ng-repeat="img in user_drive.author_imgs | filter: { parent_id: author.id }">
<img src="{{ img.img_src }}" alt="{{author.title}}" style="height:50px; border: 1px solid black;">
</div>
</a>
<div>

所以,当我点击带有“authors/{{author.title}}”ui-sref 的 anchor 标签时,我得到了那个错误。

最佳答案

我最终使用点式语法重命名了我的状态。 AFAIK,问题是我实际上并没有在子状态名称前加上其确切的父状态名称(例如:“dashboard”和“dashboard.author”),因为我认为我只需要在状态中设置父属性(例如:“parent: 'dashboard',”) 并随意命名子状态。

关于javascript - Angular UI-Router 无法从其父状态解析子状态(使用动态 URL 参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23729325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com