惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - 新房客

iOS中判断Apple Pencil力度与手触摸 Electron,VUEJS3,Vite,TypesSript 开发环境配置 安卓2022.3.11环境配置 网上设置的跨域基本都失效了,新的设置方式 从模型坐标到屏幕坐标 群晖中使用Docker安装备份升级Gitlab vscode Typescript自动修复引入类时,引号设置 基于nodejs的阿里云DDNS服务,支持多网卡绑定 WebGL与Canvas的显存与内存使用分析 基于nodejs的游戏服务器 typescript 中 d.ts module 与 namespace 区别 使用vs code与microsoft edge调试webpack项目 解决Jenkins无法编译Egret5.0项目的问题 筛选git最后一次文件列表 推荐一个不错的plist拆解工具,untp - 新房客 - 博客园 vs code(egret wing) php配置与调试 关于 typings install 的使用 angular2 环境配置 html5 js跨域
angular 引入 component 报错
新房客 · 2016-09-27 · via 博客园 - 新房客

每天抽出一些时间学习 Angular2 ,并准备把手头上的项目移植为 Angular2 , 不过今天又遇到了一些小问题。

准备写一个导航类适于管理后台常见的右边导航,如博客园的这种:

!

使用 g generate component nav-left 建立了一个名为 nav-left 的导航组件。

这里需要检查app,modile.ts中是否已经有你新建的组件。一般会自动添加,如果不存在需要添加引用:

import { NavLeftComponent } from './nav-left/nav-left.component';

模块装饰器需要添加:

@NgModule({
declarations: [
NavLeftComponent,
]
})

并在 nav-left.component.ts 中新建了一个类,Item 用来保存菜单的项,代码如下:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-nav-left',
  templateUrl: './nav-left.component.html',
  styleUrls: ['./nav-left.component.css'],
})

export class NavLeftItem{
    name:string;
    path:string;
    data:any;
    active?:string="";
}

export class NavLeftComponent implements OnInit {

  constructor() { }
}

开开心心的运行查看报错结果^^~!

报错的信息忘截图了,大致的意思是找不到这个模块,或这个模块没办法解析。

这步骤花了好长时间,最终确定问题竟然有两处,也没继续深研,分别是:

1:需要单独创建数据类。把Item单独提取一个类。 最终结果如图:

2:我在组件中写了一些预定义的数据,如下:

  //这里需要注意变量顺序,我这里是错的,因为titleList中的其他变量引用还未定义。。。。
  public titleList :Array<{"name":string,"list":any}> =[
    {"name":"后台工具","list":this.adminTool},
    {"name":"运维工具","list":this.maintenanceTool},
    {"name":"运营工具","list":this.statisticalTool},
    {"name":"GM工具","list":this.gmlTool}
  ];

  /**
   * 后台工具
   */
  public adminTool:Array<NavLeftItem> = [
    {"name":"账号列表","path":"manage/index","data":null},
    {"name":"账号权限","path":"manage/index","data":null},
    {"name":"账号密码","path":"manage/index","data":null},
    {"name":"账号添加","path":"manage/index","data":null},
    {"name":"游戏列表","path":"manage/index","data":null},
    {"name":"渠道列表","path":"manage/index","data":null},
    {"name":"渠道添加","path":"manage/index","data":null},
    {"name":"操作日志","path":"manage/index","data":null},
    {"name":"操作详情","path":"manage/index","data":null},
  ];
  /**
   * 运维工具
   */
  public maintenanceTool:Array<NavLeftItem> = [
    {"name":"Log服务器列表","path":"manage/index","data":null},
    {"name":"Log服务器添加","path":"manage/index","data":null},
    {"name":"Log入口服务列表","path":"manage/index","data":null},
    {"name":"Log入口服务配置","path":"manage/index","data":null},
    {"name":"Log服务器状态","path":"manage/index","data":null},
    {"name":"Log服务器日志","path":"manage/index","data":null},
    {"name":"Log服务器Qps统计","path":"manage/index","data":null},
    {"name":"Log服务器数据库信息","path":"manage/index","data":null},
    {"name":"Log服务器合并","path":"manage/index","data":null},
  ];

一直编译不通过,最终确定问题是顺序问题。。。很尴尬。修改顺序为:

先定义:titleList 然后定义其他几项。

问题解决。~~~~~~~~