Oingial aritial --> Link

Take away:

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

@Component({
selector : 'contacts-header',
templateUrl: './header.component.html',
styleUrls : ['./header.component.css']
})
export class HeaderComponent implements OnInit {
}

When you use `templateUrl` & `styleUrls`, the path are relative to the application root.

So if you compoennt is put inside /src/app/header. Then way `templateUrl: './header.component.html'` is refer to 'src/header.component.html', so will report 404 error.

To way to solve the problem is introduce ´moudleId: moudle.id`.

CommonJS way:

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

@Component({
moduleId: module.id, // fully resolved filename; defined at module load time
selector: 'contacts-header',
templateUrl: 'header.component.html',
styleUrls: ['header.component.css']
})
export class HeaderComponent implements OnInit {
}
//tsconfig.json

{
"compilerOptions": {
"module": "commonjs",
"target": "es5"
}
}

SystemJS:

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

@Component({
moduleId: __moduleName, // fully resolved filename; defined at module load time
selector: 'contacts-header',
templateUrl: 'header.component.html',
styleUrls: ['header.component.css']
})
export class HeaderComponent implements OnInit {
}

JSPM:

// If we decide to use JSPM, we use the typescriptOptions configuration format in the config.js file:

SystemJS.config({
typescriptOptions: {
module: "commonjs",
emitDecoratorMetadata: true,
experimentalDecorators: true
},
transpiler: false,
baseURL: "/dist",
map: {
app: 'src',
typescript: 'node_modules/typescript/lib/typescript.js',
angular2: 'node_modules/angular2',
rxjs: 'node_modules/rxjs'
},
packages: {
app: {
defaultExtension: 'ts',
main: 'app.ts'
},
angular2: {
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});

Webpack:

// require

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

@Component({
selector: 'my-app',
template: require('./header.component.html'),
styles: [require('./header.component.css')]
})
export class HeaderComponent implements OnInit {
}

or

// import

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

import { Component }  from '@angular/core';
import headerTemplate from './header.component.html';
import headerStyle from './header.component.css'; @Component({
selector : 'my-app',
template : headerTemplate,
styles : [headerStyle]
})
export class HeaderComponent implements OnInit {
}

最新文章

  1. BackTrack5-r3汉化
  2. DDD领域驱动设计之领域基础设施层
  3. git各种命令介绍以及碰到的各种坑
  4. 【bzoj1596】[Usaco2008 Jan]电话网络
  5. storm UI
  6. mysql时间格式DATE_FORMAT()
  7. 学习java第7天
  8. iOS启动图和开屏广告图,类似网易
  9. java阿拉伯数字表示的金额转换成中文大写金额
  10. 用CSS美化checkbox复选按钮和raido单选按钮-适用于移动端
  11. java 通过eclipse编辑器用mysql尝试 连接数据库
  12. vs2017 使用Bower 抛出异常ECMDERR Failed to execute "git ls-remote --tags --heads
  13. oracle查询数据字典的sql
  14. os 模块 和 os模块下的path模块
  15. java 打印图形
  16. require的压缩命令
  17. C#基础视频教程5.2 如何编写简单的超级热键
  18. 检查Linux服务器性能命令详解
  19. eclipse隐藏关闭的工程
  20. List分组迭代器 C#--深入理解类型

热门文章

  1. NET Portability Analyzer
  2. Ogre实现简单地形
  3. 设置UIButton的文字居右显示 去掉点击默认置灰效果
  4. C语言程序设计做题笔记之C语言基础知识(上)
  5. Android java程序获取assets资产文件
  6. MyEclipse10.6导出war包出错
  7. 【BZOJ 3122】 [Sdoi2013]随机数生成器 (BSGS)
  8. TeeChart中Axis的CalcIncrement属性
  9. spm_预处理实验记录
  10. HDU 5949 Relative atomic mass 【模拟】 (2016ACM/ICPC亚洲区沈阳站)