【问题标题】:Angular 1.5, ui-router + resource + components, stateProvider can't find componentAngular 1.5,ui-router + 资源 + 组件,stateProvider 找不到组件
【发布时间】: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


【解决方案1】:

是的,问题已解决。 $stateProvider.state 中无需标记组件标签

【讨论】:

    猜你喜欢
    • 2016-12-09
    • 2016-10-05
    • 2016-09-10
    • 2017-02-25
    • 2016-12-01
    • 2016-10-30
    • 2016-09-12
    • 2016-01-02
    • 2016-11-15
    相关资源
    最近更新 更多