angular2學習遇到的注意點


關於angular2里面使用了templateUrl的時候設置moduleId其實是用於解析樣式表和模板的相對路徑,如文檔中所述。

包含組件的模塊的模塊標識。需要能夠解析模板和樣式的相對網址。在Dart中,這可以自動確定,不需要設置。在CommonJS中,這總是可以設置為module.id。

ref(old):https : //angular.io/docs/js/latest/api/core/index/ComponentMetadata-class.html

我們可以通過設置@Component元數據的moduleId屬性來指定模板和樣式文件相對於組件類文件的位置

ref:https//angular.io/docs/ts/latest/cookbook/component-relative-paths.html

文件夾結構示例:

RootFolder
├── index.html
├── config.js
├── app
│   ├── components
│   │   ├── my.component.ts
│   │   ├── my.component.css
│   │   ├── my.component.html


沒有module.id

@Component({
  selector: 'my-component',
  templateUrl: 'app/components/my.component.html', <- Starts from base path
  styleUrls:  ['app/components/my.component.css'] <- Starts from base path
})

使用module.id

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs", <- need to change this if you want to use module.id property
...

 

@Component({
  moduleId: module.id,
  selector: 'my-component',
  templateUrl: 'my.component.html', <- relative to the components current path
  styleUrls:  ['my.component.css'] <- relative to the components current path
})

2.angular2路由里面重定向里面關於pathMatch的說明

它能做什么

表示路由器配置。

接口概述

interface Routes {

}

接口說明

 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM