了解相对和绝对路径 javascript
Under standingrelative and abolute path javascript
谁能帮我理解相对路径和绝对路径的概念。我真的很困惑他们是如何在我所在的目录中工作的?
我有以下代码我不能包含 PostService 模块。
import { Component } from '@angular/core';
import { PostService } from '../services/post.service';
@Component({
moduleId: module.id,
selector: 'search',
templateUrl: 'search.component.html',
providers:[PostService]
})
export class SearchComponent {
posts: post[];
constructor(){
this.posts = [
{
id: 1,
title:"Post heading",
body: "They want a self-starter. They don't need more handholding than necessary. They want someone whos not a script kiddy, who knows solid software engineering fundamentals. They want someone who will work well with the team, and be proactive in improving the situation, rathe t just playing the victim when things go wrong."
},
{
id: 2,
title:"Post heading",
body: "They want a self-starter. They don't need more handholding than necessary. They want someone whos not a script kiddy, who knows solid software engineering fundamentals. They want someone who will work well with the team, and be proactive in improving the situation, rathe t just playing the victim when things go wrong."
},
{
id: 3,
title:"Post heading",
body: "They want a self-starter. They don't need more handholding than necessary. They want someone whos not a script kiddy, who knows solid software engineering fundamentals. They want someone who will work well with the team, and be proactive in improving the situation, rathe t just playing the victim when things go wrong."
}
]
}
}
文件结构如下:
-- app
'-- components
'-- search
'-- search.component
'-- services
'-- post.service
如果您设置 moduleId: module.id,
,那么您的 templateUrl
和 styleSheetsUrl
路径将相对于您所在的当前目录。
因此,如果您使用 ../
进入上一层,您将进入组件目录。您需要再上一层才能进入您的服务文件夹所在的应用程序目录。
所以路径应该是:../../services/post.service
谁能帮我理解相对路径和绝对路径的概念。我真的很困惑他们是如何在我所在的目录中工作的? 我有以下代码我不能包含 PostService 模块。
import { Component } from '@angular/core';
import { PostService } from '../services/post.service';
@Component({
moduleId: module.id,
selector: 'search',
templateUrl: 'search.component.html',
providers:[PostService]
})
export class SearchComponent {
posts: post[];
constructor(){
this.posts = [
{
id: 1,
title:"Post heading",
body: "They want a self-starter. They don't need more handholding than necessary. They want someone whos not a script kiddy, who knows solid software engineering fundamentals. They want someone who will work well with the team, and be proactive in improving the situation, rathe t just playing the victim when things go wrong."
},
{
id: 2,
title:"Post heading",
body: "They want a self-starter. They don't need more handholding than necessary. They want someone whos not a script kiddy, who knows solid software engineering fundamentals. They want someone who will work well with the team, and be proactive in improving the situation, rathe t just playing the victim when things go wrong."
},
{
id: 3,
title:"Post heading",
body: "They want a self-starter. They don't need more handholding than necessary. They want someone whos not a script kiddy, who knows solid software engineering fundamentals. They want someone who will work well with the team, and be proactive in improving the situation, rathe t just playing the victim when things go wrong."
}
]
}
}
文件结构如下:
-- app
'-- components
'-- search
'-- search.component
'-- services
'-- post.service
如果您设置 moduleId: module.id,
,那么您的 templateUrl
和 styleSheetsUrl
路径将相对于您所在的当前目录。
因此,如果您使用 ../
进入上一层,您将进入组件目录。您需要再上一层才能进入您的服务文件夹所在的应用程序目录。
所以路径应该是:../../services/post.service