angular-components

Cannot read property 'viewContainerRef' of undefined

我的未来我决定 提交于 2020-08-24 05:10:18
问题 I am trying to display a dynamic component similar (not exact) to the example in angular docs. I have a dynamic directive with viewContainerRef @Directive({ selector: '[dynamicComponent]' }) export class DynamicComponentDirective { constructor(public viewContainerRef: ViewContainerRef) { } } Excerpt from component code @ViewChild(DynamicComponentDirective) adHost: DynamicComponentDirective; .. ngAfterViewInit() { let componentFactory = null; console.log(component); componentFactory = this

Angular exported component from module not useable in another module

回眸只為那壹抹淺笑 提交于 2020-08-23 03:07:09
问题 I am exporting a custom component in my AppModule but can not use it in another module, which is being imported in the AppModule. I thought exported components are visible globally? I am trying to use the CalendarComponent with the selector 'app-calendar' in a component within the TestModule. app.module.ts @NgModule({ declarations: [ ... , CalendarComponent, ], imports: [ ... , TestModule, ], exports: [ ... CalendarComponent, ], providers: [ ... ], bootstrap: [AppComponent] }) test.module.ts

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

有些话、适合烂在心里 提交于 2020-08-08 06:13:17
问题 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 some inline changes. So, this might not be a compiler happy code. My Reactive Component: @Component({ selector: 'text-input', templateUrl: '<input type="text" class="native_input" />' }) class TextInput implements ControlValueAccessor { protected

Apply attribute directive on component in Angular 4

孤街浪徒 提交于 2020-08-04 04:43:44
问题 I have created img-pop component which has @Input() bind property src. I have created authSrc directive which has @HostBinding() property src. @Component({ selector: 'img-pop', template: `<img [src]="src"/> <div *ngIf="isShow"> <----extra value-----> </div>` }) export class ImgPopOverComponent implements OnInit { @Input() private src; private isShow=false; @HostListener('mouseenter') onMouseEnter() { this.isShow= true; } @HostListener('mouseleave') onMouseLeave() { this.isShow= false; } } I