日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于 Angular 项目里的 index.ts

發布時間:2023/12/19 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于 Angular 项目里的 index.ts 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如下圖所示:如果我需要在文件夾 A 里的某文件,訪問文件夾 B 里的某服務,而文件夾 A 和 B 分別是兩個不同 module 的實現,我需要在文件夾 A 的文件里,通過導入文件夾 B 里定義的 index 文件,來導入其暴露的服務,下面的例子里導入的是 BrowserService.

Jerryindex.ts 文件的內容:

如果 browser 文件下定義的是符合 Angular 命名規范的 index.ts 文件,則文件夾A里的導入語句,可以不顯式包含 index.ts 這個文件名,簡寫成:

實際上,這些 index.ts 文件,稱為 barrel file,在這個StackOverflow thread里有討論。

桶是一種將多個模塊的導出匯總到單個便利模塊的方法。 桶本身是一個模塊文件,用于重新導出其他模塊的選定導出。

Imagine three modules in a heroes folder:

// heroes/hero.component.ts export class HeroComponent {}// heroes/hero.model.ts export class Hero {}// heroes/hero.service.ts export class HeroService {}

如果沒有桶,消費者將需要三個導入語句:

import { HeroComponent } from '../heroes/hero.component.ts'; import { Hero } from '../heroes/hero.model.ts'; import { HeroService } from '../heroes/hero.service.ts';

我們可以將一個桶添加到導出所有這些項目的 heros 文件夾(按慣例稱為索引):

export * from './hero.model.ts'; // re-export all of its exports export * from './hero.service.ts'; // re-export all of its exports export { HeroComponent } from './hero.component.ts'; // re-export the named thing

現在消費者可以從桶中進口它需要的東西。

import { Hero, HeroService } from '../heroes'; // index is implied

更多Jerry的原創文章,盡在:“汪子熙”:

總結

以上是生活随笔為你收集整理的关于 Angular 项目里的 index.ts的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。