[Angular] Omit relative path by set up in tsconfig.json
2023-09-14 08:59:18 时间
For example, inside you component you want to import a file from two up directory:
import store from '../../store'
This becomes a little bit problematic because the component can be really nested.
To solve this problem, we can define "paths" in tsconfig.json:
{ ... "compilerOptions": { "baseUrl": ".", "paths": { "store": ["src/store.ts"] }, ... "target": "es5" } }
Now for each component, we can just use:
import store from 'store'
相关文章
- [ngx-formly] Dynamically set Model Properties with Angular Formly Expressions
- [NPM] Set default values for package.json using npm set
- [Angular] ngx-formly (AKA angular-formly for Angular latest version)
- [Angular & Unit Testing] Testing a RouterOutlet component
- [Angular 2] BYPASSING PROVIDERS IN ANGULAR 2
- [Angular2 Form] Build Select Dropdowns for Angular 2 Forms
- [Angular 2] Set Properties on Dynamically Created Angular 2 Components
- [AngularJS] Isolate State Mutations in Angular Components
- [Angular 2] ROUTING IN ANGULAR 2 REVISITED
- [AngularJS] Angular 1.3 Anuglar hint
- [Angular] Service facotry(), custom filter
- [ngx-formly] Dynamically set Model Properties with Angular Formly Expressions
- [Angular] Scrolling the Message List To the Bottom Automatically Using OnChanges
- [Angular 2] Set Properties on Dynamically Created Angular 2 Components
- [Angular 2] Create Shareable Angular 2 Components
- 关于 Angular 工程文件 angular.json 里的 inlineCritical 属性
- Angular NgModule providers字段维护了多个字段后的初始化实现
- Angular和SAP C4C的事件处理队列
- 运行在 SSR 模式下的 Angular 应用的内存泄漏问题分析
- Angular自定义structural指令的实例化过程以及set方法的调用
- Angular应用的入口