首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularJS UI-路由器不会显示所有组件(只显示一些组件)

AngularJS UI-路由器不会显示所有组件(只显示一些组件)
EN

Stack Overflow用户
提问于 2018-08-04 20:09:23
回答 1查看 51关注 0票数 1

我已经成功地复制了我的问题与叉的“你好银河!”嵌入到UI-路由器教程页中。

My plunkhttps://plnkr.co/edit/2GqCtEJ4mhBIdJOFHy9c?p=preview

关于现有的“直升机银河!”我添加了以下模块和路由配置:

代码语言:javascript
复制
// file: hello.js
//     existing "Hello Galaxy!" hello module code above this ↑↑↑
//     then my new module below...

angular.module('hello.product-management', ['ui.router']).config(function($stateProvider) {
    // An array of state definitions
    var states = [
    {
        name: 'product-management-template',
        url: '/product-management-template',
        // Using component: instead of template:
        template: '<h1>Product Management</h1>'
    },
    {
        name: 'product-management-component',
        url: '/product-management-component',
        // Using component: instead of template:
        component: 'product-management'
    },

    ]

    // Loop over the state definitions and register them
    states.forEach(function(state) {
        $stateProvider.state(state);
    });
});

问题:您可以单击选项卡查看产品管理模板,如下所示:

但是您不能使用选项卡查看component模板。它只显示一个空视图:

我留下了原来的“你好银河!”普伦克的组件和路线,它们仍然可以正常工作:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-04 20:54:21

在状态定义中,使用camelCase作为组件名称:

代码语言:javascript
复制
{
    name: 'product-management-component',
    url: '/product-management-component',
    // Using component: instead of template:
    ̶c̶o̶m̶p̶o̶n̶e̶n̶t̶:̶ ̶'̶p̶r̶o̶d̶u̶c̶t̶-̶m̶a̶n̶a̶g̶e̶m̶e̶n̶t̶'̶
    component: 'productManagement'
},

并使用camelCase定义组件

代码语言:javascript
复制
̶a̶p̶p̶.̶c̶o̶m̶p̶o̶n̶e̶n̶t̶(̶'̶p̶r̶o̶d̶u̶c̶t̶-̶m̶a̶n̶a̶g̶e̶m̶e̶n̶t̶'̶,̶ ̶{̶
app.component('productManagement', {

  template: '<h1>Product Management</h1>',
  controller: function () {
    console.log("product management component");
  }      
});

有关更多信息,请参阅AngularJS开发人员指南-指令规范化

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51689211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档