ng-container vs ng-template

  • <ng-container> if you need a helper element for nested structural directives like ngIf or ngFor or if you want to wrap more than one element inside such a structural directive;
  • <ng-template> if you need a view "snippet" that you want to stamp at various places using ngForTemplate, ngTemplateOutlet, or createEmbeddedView().

ng-template is used for structural directive like ng-if, ng-for and ng-switch. If you use it without structural directive, nothing happens and renders.

ng-container is used when you don't have a suitable wrapper or parent container. In most cases we are using div or span as a container but in such a cases when you want to use multiple structural directive, but you can't use more than one structural directive on a element, in that case ng-container can be used as a container

Похожие записи

Как добавить ng-bootstrap компоненты в проект Angular-CLI?

Покажу на примере нового проекта.

ng new project_name
cd project_name
npm install --save bootstrap@next
npm install --save @ng-bootstrap/ng-bootstrap

В angular-cli.json в секцию style надо добавить наш CSS, чтобы глобально подключить стили.

  "styles": [

Отладка Angular в VS Code

Настройка Visual Studio Code используя расширение Debugger for Chrome для отладки Angular приложений

Angular. Can't set breakpoints in VS Code

Вариант решения проблемы, когда не срабатывают точки остановки при разработке Angular приложений в редакторе VS Code