Unable to use child component in a parent component in Angular2
You had typo inside child-component
meta options.
templateUrl: `<p>Child Component</p>`
should be
template: `<p>Child Component</p>`
Can't access child from parent component in angular
export class Editor implements OnInit, OnDestroy {
@ViewChild(FilePickerComponent) filePicker!: FilePickerComponent;
async save() {
}
In the above code the implementation for the AfterViewInit life cycle hook is missing.In angular documentation it states that this life cycle hook is important.
Angular documentation for component intreactions
Try changing the above code as following
import {
Component,
OnInit,
ViewChild,
OnDestroy,
AfterViewInit
} from "@angular/core";
export class Editor implements OnInit, OnDestroy,AfterViewInit {
@ViewChild(FilePickerComponent) filePicker!: FilePickerComponent;
async save() {
}
Angular communication between parent and child using @Input components doesn't work but gives no errors
Actually you need to call Parent Component to parse your @input
to the Child Component. you are directly calling the child selector that is why your not able to displaying anything.
So, call the Parent Component in app.component.html to get input string,
<app-parent></app-parent>
Styling not applying to child component
It's because by default components have view encapsulation (shadow dom). To disable this behavior, you can leverage the encapsulation
attribute, as described below:
import {Component, ViewEncapsulation} from '@angular/core';
import {TestApp} from 'testapp.component.ts';
@Component({
selector:'test-component',
styleUrls: ['test.component.css'],
templateUrl: './test.component.html',
directives:[TestApp],
encapsulation: ViewEncapsulation.None // <------
})
export class TestComponent{
}
See this plunkr: http://plnkr.co/edit/qkhkfxPjgKus4WM9j9qg?p=preview.
Angular component communication parent - child not working
Try this:
<app-portalcard *ngFor="let portalcard of portalcards" [portalcard]="portalcard">
</app-portalcard>
Instead of your code:
<app-portalcard *ngFor="let portalcard of portalcards">
[portalcard]="portalcard"
</app-portalcard>
Related Topics
CSS Not Loading in Firefox, Opera and Ie - Chrome and Safari Works Just Fine
Change Icon from Jquery UI to Fontawesome in Primefaces
How Md-Icons Are Rendered on Browser
†Appearing Instead of Quotation Marks
How to Mask a <Div>, or to Overlay Text with a Masked Image
CSS on Parent Hover Keep Child Not Filter-Grayscaled
Question About CSS Files for Smartgwt Project
How to Center Div in The Page? (Height & Width)
How to Draw Vertical Separators in The Interior Gaps of a CSS Grid of Varying Columns
Adding Call Outs to a Highcharts - Stacked Bar
Vertical Vim Cursor in Command Mode
Can a Div Fill Up The Entire Viewport with a Pixel-Based Margin, Not Using The CSS3 Calc Property
CSS Hoverable Dropdown Menu Doesn't Close on Mobile
What Is The 'Best Practice' Way of Creating an Icon Button with an Svg
Displaying Third Tier Submenus Properly with CSS Only Menu