0

i would like use nested component. This fine tutorial shows, how could i do that:

https://www.themarketingtechnologist.co/building-nested-components-in-angular-2/

My problem is, that my template for the nested component will not be found: I have try

template: '<h2>HALLO</h2>'

But i would like use extern file: task.component.html like this:

 template: 'file.component.html'

Output is, that simply

task.component.html

will be displayed and when i try:

templateUrl: 'file.component.html'

i get error:

Uncaught (in promise): Failed to load task.component.html

Here is my code:

ChildComponent:

@Component({

    selector: 'edit-task',
    templateUrl: 'file.component.html'

})
export class FileFormat{}

ParentComponent:

@Component({
    moduleId: module.id,
    selector: 'my-app',
    templateUrl: 'app.template.html',
    directives: [FileFormat]
})
export class FileFormat{}

1 Answer 1

1

try this code

@Component({
    moduleId: module.id
    selector: 'edit-task',
    templateUrl: 'file.component.html'

})
export class FileFormat{}

actually the problem is angular is not getting the path properly , to use it relative path use moduleID

or either give the full path in telplateUrl from the root

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.