2016-12-05 13 views
2

相対パスと絶対パスの概念を理解してもらえますか?私は彼らがどのディレクトリにいるのか、私は本当に混乱していますか? 私は以下のコードを持っています。私はPostServiceモジュールを含めることができません。次のように下位および下位パスの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." 
     } 
    ] 
    } 
} 

ファイルの構造は次のとおりです。

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

答えて

1

あなたがmoduleId: module.id,を設定した場合、あなたのtemplateUrlstyleSheetsUrlパスはあなたがしているカレントディレクトリからの相対なっ

ので、あなたは1、上に行く場合レベルが../の場合は、componentsディレクトリにあります。サービスフォルダがあるアプリケーションディレクトリに入るためには、さらに1つ上の階層に移動する必要があります。

ので、パスは次のようになります。../../services/post.service

+1

あなたは私が助けることができるうれしい –

+0

@AhmadAbdullahを@echonax感謝。 – echonax

関連する問題