Angular路径:从与当前目录级别相同的文件夹获取文件
创始人
2024-10-28 00:30:30
0

在Angular中,可以使用相对路径来从与当前目录级别相同的文件夹获取文件。以下是一种解决方法的代码示例:

假设我们有以下文件结构:

  • app
    • components
      • component1
        • component1.component.ts
      • component2
        • component2.component.ts
    • services
      • data.service.ts

现在,如果我们想从component1.component.ts文件中引用data.service.ts文件,可以使用以下相对路径:../services/data.service.ts

component1.component.ts:

import { Component } from '@angular/core';
import { DataService } from '../services/data.service';

@Component({
  selector: 'app-component1',
  template: '

Component 1

', }) export class Component1Component { constructor(private dataService: DataService) { // 使用dataService } }

同样,如果我们想从component2.component.ts文件中引用data.service.ts文件,可以使用相同的相对路径:../services/data.service.ts

component2.component.ts:

import { Component } from '@angular/core';
import { DataService } from '../services/data.service';

@Component({
  selector: 'app-component2',
  template: '

Component 2

', }) export class Component2Component { constructor(private dataService: DataService) { // 使用dataService } }

通过使用相对路径,我们可以从与当前目录级别相同的文件夹获取所需的文件。

相关内容

热门资讯

外挂教程书!xpoker辅助工... 外挂教程书!xpoker辅助工具,云扑克有透视吗-都是有辅助神器(哔哩哔哩)所有人都在同一条线上,像...
外挂办法!poker worl... 外挂办法!poker world辅助,werplan外卦神器-一贯真的有辅助方法(哔哩哔哩)1)we...
外挂模板!德州透视是真的假的,... 您好,德州透视是真的假的这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多...
外挂窍要!约局吧开挂,德州之星... 外挂窍要!约局吧开挂,德州之星扫描器-一贯一直总是有辅助工具(哔哩哔哩)1、用户打开应用后不用登录就...
外挂讲义!agpoker辅助,... 外挂讲义!agpoker辅助,wepoker透视有吗-切实真的有辅助插件(哔哩哔哩)1、任何wepo...
外挂方案!pokerworld... 外挂方案!pokerworld辅助器,菠萝辅助器免费版的功能介绍-一贯一直总是有辅助技巧(哔哩哔哩)...
外挂大纲!约局吧德州真的有透视... 外挂大纲!约局吧德州真的有透视挂吗,德普之星私人局辅助器-原来有辅助软件(哔哩哔哩)1、约局吧德州真...
外挂绝活!xpoker辅助助手... 外挂绝活!xpoker辅助助手,佛手在线大菠萝智能辅助器-真是是真的有辅助工具(哔哩哔哩);1、每一...
外挂手段!哈糖大菠萝破解器,德... 外挂手段!哈糖大菠萝破解器,德普之星有透视辅助吗-本来有辅助工具(哔哩哔哩)1、金币登录送、破产送、...
外挂法门!智星德州有脚本吗,德... 外挂法门!智星德州有脚本吗,德州透视竞技联盟-好像一直总是有辅助插件(哔哩哔哩)德州透视竞技联盟破解...