Questions tagged [angular2-ngcontent]

88 questions
39
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.
  • 2,604
  • 3
  • 19
  • 31
34
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
  • 793
  • 2
  • 10
  • 21
19
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
  • 3,842
  • 4
  • 34
  • 61
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
  • 185
  • 2
  • 12
11
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
  • 2,962
  • 4
  • 33
  • 63
10
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…
10
votes
2 answers

conditional ng-content in angular 4/5

Hi I want some conditional implementation of ng-content e.g.
Mantu Nigam
  • 2,593
  • 4
  • 20
  • 38
10
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,035
  • 3
  • 16
  • 32
9
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
  • 93
  • 1
  • 4
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
  • 510
  • 9
  • 21
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
  • 8,916
  • 11
  • 50
  • 86
6
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
  • 619
  • 5
  • 30
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
5
votes
2 answers

Angular 4 ngComponentOutlet loads dynamic components, but route content is not being rendered

I'm trying to load different 'parent' components and inject route content into these different parent components by targeting ng-content in each parent component. Essentially, each parent component handles the navigation and other boilerplate stuff…
Tom Schreck
  • 4,669
  • 11
  • 60
  • 118
5
votes
1 answer

Angular2 @ContentChildren not populated inside parent

ISSUE: @ContentChildren does not seem to work on Parent containers. Even if the content is a child of the component. Plunker: https://plnkr.co/edit/J5itJmDfwKwtBsG6IveP?p=preview NOTE: I Am using {descendants: true} Example Code: Main…
Kevin Upton
  • 2,419
  • 1
  • 18
  • 24
1
2 3 4 5 6