Câu hỏi phỏng vấn Angular
Câu hỏi

What is the option to choose between Inline and External template file?

Câu trả lời

In Angular, when defining a component's template, you have the option to choose between using an inline template or an external template file. This choice is specified within the component's metadata using the @Component decorator.

  • Inline Template: You can define the template directly within the TypeScript file of the component using the template property. This is typically used for small, simple templates for the sake of convenience and to keep the template close to the component code. Here's an example of an inline template:

    @Component({
      selector: 'my-app',
      template: `
        <h1>Hello World</h1>
        <p>This is an inline template.</p>
      `
    })
    export class AppComponent { }
  • External Template File: Alternatively, you can define the template in a separate HTML file and link to it using the templateUrl property. This approach is preferred for larger, more complex templates to improve readability and maintainability. Here's an example of using an external template file:

    @Component({
      selector: 'my-app',
      templateUrl: './app.component.html'
    })
    export class AppComponent { }

The Angular CLI, by de...

middle

middle

Gợi ý câu hỏi phỏng vấn

junior

What is the difference between Structural and Attribute directives in Angular?

expert

Angular 8: What are some changes in Location module?

junior

What is an Observer ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào