2016-12-05 1 views
2

Kann mir bitte jemand helfen mit Verständnis der relativen und absoluten Pfade. Ich bin wirklich verwirrt, wie sie in welchem ​​Verzeichnis ich arbeite? Ich habe diesen folgenden Code Ich kann PostService-Modul nicht enthalten.Unter standingrelative und abolute path javascript

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." 
     } 
    ] 
    } 
} 

Dateistruktur ist wie folgt:.

-- app 
    '-- components 
     '-- search 
      '-- search.component 
    '-- services 
     '-- post.service 

Antwort

1

Wenn Sie setzen moduleId: module.id, dann templateUrl und styleSheetsUrl Pfade in das aktuelle Verzeichnis relativiert Sie sind

wenn Sie also 1 obere gehen Ebene mit ../ werden Sie im Komponentenverzeichnis sein. Sie müssen 1 weitere obere Ebene gehen, um in dem App-Verzeichnis zu sein, in dem sich Ihr Dienstordner befindet.

werden, so sollte der Pfad: ../../services/post.service

+1

danke –

+0

@AhmadAbdullah Glad @echonax ich helfen konnte. – echonax

Verwandte Themen