Question from the Angular 4 (legacy) test

How to get the parent element of a child element in AngularJS

Expert

Given the following code

const routes: Routes = [{
    path: 'parent',
    component: AbstractParentComponent,
    children: [
        {
            path: '',
            component: ParentComponent
        },
        {
            path: 'child',
            component: ChildComponent
        }
    ]
}];

With the following components:

// abstractparent.component.ts
import {Component} from '@angular/core';

@Component({
    selector: 'app-abstract-parent',
    template: 'Parent: <router-outlet></router-outlet>'
})
export class AbstractParentComponent {
    constructor() {
    }
}
// parent.component.ts
import {Component} from '@angular/core';

@Component({
    selector: 'app-parent',
    template: 'Parent'
})
export class ParentComponent {
    constructor() {
    }
}
// child.component.ts
import {Component} from '@angular/core';

@Component({
    selector: 'app-child',
    template: '<p>child</p>'
})
export class ChildComponent {
    constructor() {
    }
}

What will the page at the URL /parent/child display?

Author: Mathieu RobinStatus: PublishedQuestion passed 440 times
Edit
1
Community Evaluations
developer avatar
koceila
04/11/2023
j'ai répondu "child" (template du ChildComponent ). est ce bien la bonne réponse ?