【发布时间】:2017-02-28 19:59:56
【问题描述】:
我的应用程序的结构如下:
app/
js/
levels/
level-create
level-edit
level-list/
level-list.template.html
levellist.component.js
level-show/
level-show.template.html
levelshow.component.js
levels.module.js
我也有基本的资源服务,我将其注入到每个组件和路由文件中:
'use strict';
module.exports = angular
.module('app.levels.route', [])
.config(function($stateProvider) {
$stateProvider.state({
component: 'levellist',
name: 'levelIndex',
url: '/levels',
template: '<levellist></levellist>'
}).state({
component: 'levelshow',
name: 'levelShow',
url: 'levels/:id',
template: '<levelshow></levelshow>'
});
});
使用 levellist 组件一切正常,但使用 levelshow 它只是找不到这个组件...我还注意到 stateProvider 组件的搜索引擎非常具体。 还有levelshow.component.js
'use strict';
var angular = require('angular');
module.exports = angular
.module('app.levelsshow.component', ['ngMaterial'])
.component('levelshow', {
controller: LevelShowController,
templateUrl: '/app/js/levels/components/level-show/level-show.template.html'
});
LevelShowController.$inject = ['Level', '$scope', '$stateParams'];
function LevelShowController(Level, $scope, $stateParams) {
$scope.levelShow = Level.get({ id: $stateParams.id });
}
【问题讨论】:
-
“崩溃”是什么意思?也许是一些日志?
-
这里有一个多模块应用程序。你不需要将levelshow的模块
app.levelsshow.component作为依赖注入app.levels.route吗? -
在我看来路由文件找不到下一个组件级别显示,所以它只是不显示任何错误。我将所有这些都注入到一个模块 level.module.js 中。我需要所有这些文件,因此它可以与 levellist.component.js 一起使用
标签: angularjs angular-ui-router resources components