gpt4 book ai didi

javascript - Angular uirouter 打开错误的网址

转载 作者:行者123 更新时间:2023-12-01 02:36:34 26 4
gpt4 key购买 nike

我是 Angular 1 的新手,必须在现有的 Web 应用程序上实现新功能。该应用程序使用 jhipster 生成后端和前端的某些部分(Angular 1 和 uirouter)。

因此,我尝试使用自己的路由和状态,如下所示,这主要是从网络应用程序的现有组件中复制和粘贴的:

(function() {
'use strict';

angular
.module('artemisApp')
.config(stateConfig);

stateConfig.$inject = ['$stateProvider'];

function stateConfig($stateProvider) {
$stateProvider
.state('model-comparison-exercise-for-course', {
parent: 'entity',
url: '/course/{courseid}/model-comparison-exercise',
data: {
authorities: ['ROLE_ADMIN', 'ROLE_TA'],
pageTitle: 'artemisApp.modelComparisonExercise.home.title'
},
views: {
'content@': {
templateUrl: 'app/entities/model-comparison-exercise/model-comparison-exercise.html',
controller: 'ModelComparisonExerciseController',
controllerAs: 'vm'
}
},
resolve: {
translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
$translatePartialLoader.addPart('modelComparisonExercise');
$translatePartialLoader.addPart('exercise');
$translatePartialLoader.addPart('global');
return $translate.refresh();
}],
courseEntity: ['$stateParams', 'Course', function ($stateParams, Course) {
return Course.get({id: $stateParams.courseid}).$promise;
}]
}
});
}

})();

然后我尝试使用以下代码打开此路由:

<a ui-sref="model-comparison-exercise-for-course({courseid:course.id})"
data-translate="artemisApp.course.modelComparisonExercises"></a>

通过单击该链接,将触发 http get 请求,该请求返回 http 状态代码 404:http://localhost:8080/app/entities/model-comparison-exercise/model-comparison-exercise.html

实际上,应该打开的网址是http://localhost:8080/#/course/1/model-comparison-exercise

知道我可能配置错误吗?

最佳答案

请尝试更改 'content@''content@artemisApp' .

如上所述here :

The symbol before the @ is the name of the view you want to match, and the symbol after the @ is a reference to the state in which the template the ui-view directive should exist in.

还有<a>标签未关闭:

<a ui-sref="model-comparison-exercise-for-course({courseid:course.id})"
data-translate="artemisApp.course.modelComparisonExercises"></a>

搜索代码,发现model-comparison-exercise.html文件夹 model-comparison-exercise 中不存在。另外model-comparison-exercises.html存在。

关于javascript - Angular uirouter 打开错误的网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47859490/

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