Questions tagged [angular-components]

A component controls a patch of screen called a view. Component decorator allows you to mark a class as an Angular component and provide additional metadata that determines how the component should be processed, instantiated and used at run time.

Components are the most basic building block of an UI in an Angular application. An Angular application is a tree of Angular components. Angular components are a subset of directives. Unlike directives, components always have a template and only one component can be instantiated per an element in a template.You can see more information on components here

2024 questions
12
votes
2 answers

Angular Component Constructor Called Twice

I am new to Angular and am running into an issue with the constructor on a child component being called twice, and the second time it is called it is clearing the properties set the first time. This is the parent component: @Component({ …
rwdial
  • 323
  • 1
  • 4
  • 9
12
votes
2 answers

How to access parent component in angularjs 1.5

Hi i am trying to display simple components in angularjs where child needs to access parent name.And my code goes like this: HTML file:
Ambar Bhatnagar
  • 215
  • 1
  • 3
  • 9
11
votes
3 answers

Angular - How to set default values for optional input properties

I wonder what is the "Angular/Typescript way" to set up default values for optional properties in Angular component? I am having troubles when values passed to optional properties are null or undefined. Currently I am having something like…
Allwe
  • 471
  • 1
  • 5
  • 18
11
votes
1 answer

How to implement ControlValueAccessor on downgraded Angular component

I have an Angular component that implements ControlValueAccessor, but the writeValue method is never called with the initial value from ngModel. template: the component is downgraded to AngularJS…
David Fregoli
  • 3,377
  • 1
  • 19
  • 40
11
votes
1 answer

pass data through using component interaction in angular2

I'm trying to use this technique intercept input property changes with a setter to pass some data from a parent component to a child component and call a method in child component when the value is changed. my problem is the child component is…
11
votes
2 answers

Angular 1.5+ component optional one-way binding

Taken from the AngularJS 1 documentation: You can also make the binding optional by adding ? :
Glenn Mohammad
  • 3,871
  • 4
  • 36
  • 45
11
votes
4 answers

Angular2: Input setter not picking up set event if value does not change

Referring to Angular2 documentation file here: [https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#parent-to-child-setter] (Parent to child setter), I have the following child component code: import { Component, Input } from…
Ayyash
  • 4,257
  • 9
  • 39
  • 58
11
votes
3 answers

How to dynamically create component instance with input/output from a service and inject it to DOM separately?

In creating dynamic components in Angular 2, I found out that this process requires ViewContainerRef in order to add newly created component to DOM. And in passing @Input and @Outputto those dynamically created components, I found the answer in the…
Dangular
  • 389
  • 1
  • 3
  • 15
10
votes
2 answers

How to Send FormGroup Object as Output to Parent Component from child component n Angular

I'm working in forms and I have two components: my child component contains this formGroup Object : employeeForm : FormGroup; this.employeeForm = new FormGroup({ firstName:new FormControl(), lastNAme:new FormControl(), …
James
  • 1,190
  • 5
  • 27
  • 52
10
votes
2 answers

Is it good idea to use ComponentFactoryResolver in Angular7 application?

I want to create an angular 7 web application that dynamically loads different components, as demonstrated in this official documentation: https://angular.io/guide/dynamic-component-loader But I am not sure if it's a good idea to use…
A. Zalonis
  • 1,599
  • 6
  • 26
  • 41
10
votes
2 answers

Angular Library Module generate a component from workspace

I have an Angular Workspace created with three projects. As well as I have just created a Library that I would like to have reusable modules inside. Typically for the projects (applications and library) I run the following to generate a module or…
10
votes
4 answers

How to get the child DOM element reference from Parent using angular 4

I need to get the child component DOM reference from parent component using angular 4, but i can't access child component DOM, please guide me how to achieve this. parent.component.html parent.component.ts import…
Jeyabalan Thavamani
  • 3,057
  • 8
  • 21
  • 33
10
votes
2 answers

How to Identify whether a Angular2 component is completely loaded ( including ViewChilds ) when there is ngIf in template

Is it possible to Identify whether a Angular2 component (here AppComponent) is completely loaded ( including ViewChilds ) when there ngIf in template which conditionally loads the child. Reference: Angular 2 @ViewChild annotation returns…
tymspy
  • 4,200
  • 2
  • 20
  • 35
9
votes
2 answers

How to unit test a reactive component where ngControl is decorated with @Self

I've written a reactive component by injecting the NgControl and which is decorated using the @Self decorator. My problem is related to unit testing of such component. Please look at the code below: Disclaimer: I've quickly copied the code and made…
9
votes
4 answers

Angular folder structure and component services

I have read many articles about Angular folder structure. It is still not clear to me where do we put component services. Shared services between components are put under shared. But what about a service that is used only by a component? Usually I…
pantonis
  • 5,601
  • 12
  • 58
  • 115