Questions tagged [angular2-ngcontent]

94 questions
45
votes
3 answers

How to conditionally wrap a div around ng-content

depending on the value of a (boolean) class variable I would like my ng-content to either be wrapped in a div or to not be wrapped in div (I.e. the div should not even be in the DOM) ... Whats the best way to go about this ? I have a Plunker that…
Somo S.
  • 3,997
  • 4
  • 26
  • 33
37
votes
4 answers

Angular 2 Template as a parameter to component

My simplified goal is to build a component which is a list with item template. E.g.: item Here is my code: import {bootstrap} from 'angular2/platform/browser'; import {Component} from 'angular2/core'; @Component({ selector: 'list', …
Dizzy
  • 892
  • 3
  • 12
  • 24
25
votes
3 answers

Is it possible to set default value to

I was just learning the use of Transluction in angular2 from this tutorial: https://scotch.io/tutorials/angular-2-transclusion-using-ng-content I was able to use the tag for some content like:
PaladiN
  • 4,625
  • 8
  • 41
  • 66
16
votes
2 answers

conditional ng-content in angular 4/5

Hi I want some conditional implementation of ng-content e.g.
Mantu Nigam
  • 3,690
  • 7
  • 24
  • 41
15
votes
2 answers

Is there a way to use css in ng-content inside an Angular2 component?

I tried to include css for children element included in a component via ng-content. It seems to be not implemented yet in Angular 2 or maybe someone has got a solution except to put css in a general stylesheet ? app.component.ts
J.BizMai
  • 2,621
  • 3
  • 25
  • 49
13
votes
2 answers

Angular Material Tabs not working with wrapper component

We are developing a corporate component library which should provide Material Designed Angular Components. So the users of this library are not supposed to use e.g. Angular Material directly but rather include some component like…
13
votes
3 answers

Capture event on ng-content in Angular 2

I am going through this tutorial to comprehend angular 2's ng-content. I want to capture event which is triggered on ng-content. I have following component: @Component({ moduleId: module.id, selector: 'card', template: `
Hitesh Kumar
  • 3,508
  • 7
  • 40
  • 71
13
votes
2 answers

Instantiate transcluded components depending on their DOM state in angular 2

Common menu usage case menu template
I was suprised to hear that all…
drow
  • 194
  • 3
  • 15
11
votes
1 answer

Creating a dynamic repeater with ng-content transclusion

What I'm trying to achieve is a generic component that is bound to an array of arbitrary objects that allows adding and removing rows dynamically when the view of each row is also arbitrarily defined with components by a master component that uses…
VRuter
  • 113
  • 1
  • 6
10
votes
1 answer

Angular 2+ NgTemplateOutlet inside ngFor

We have some arrays like: heroes: Hero[]; villains: Villain[]; ... puppies: Puppy[] and a template like

{{ individual.name }} - {{ individual.mobileNumber }} ...

sevic
  • 879
  • 11
  • 36
8
votes
0 answers

How can I use ContentChild/Children in nested

I am successfully using to show a component in a grandchild as answered here: Father-to-son component tree with guest component, but now I would like to use @ContentChild in that grandchild to access the passed in content,…
Learning2Code
  • 521
  • 9
  • 21
7
votes
1 answer

inputs are not considered in form validation when using ng-content

Given the following component (with selector my-template):
and use it like this:
7
votes
3 answers

Angular 2 referencing dynamic instance of @ContentChild

I'm using Angular 2.0.1. I have a component that can take in any other component via -- this works great. The issue I run into is when I want to reference the injected component. If I knew that would only ever be one…
Hanna
  • 10,315
  • 11
  • 56
  • 89
6
votes
2 answers

ng-content vs. ng-template

What is the difference between ng-content and ng-template, and what are some different use-cases for each of them?
geraktOfRivia
  • 325
  • 3
  • 7
  • 19
6
votes
1 answer

Multiple transclusion using ngFor in Angular2

I'm pretty new in angular2 and I'm trying to make a small angular component called "grid" that simply rearranges its content using transclusion. Its template grid component template (grid.component.ts)
Jman
  • 63
  • 7
1
2 3 4 5 6 7