2

Can someone please help me with understanding concept of relative and absolute paths. I am really confused how they work in what directory I am ? I have this following code I can't include PostService module.

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

File structure is as follows:

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

1 Answer 1

1

If you set moduleId: module.id, then your templateUrl and styleSheetsUrl paths become relative to the current directory you are in.

so if you go 1 upper level with ../ you will be in the components directory. You need to go 1 more upper level in order to be in the app directory where your services folder is.

So the path should be: ../../services/post.service

Sign up to request clarification or add additional context in comments.

1 Comment

@AhmadAbdullah Glad I could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.