Angular 角度4:ng模板内的组件参考
我是新手。 我想在ng模板中处理组件(验证警报)Angular 角度4:ng模板内的组件参考,angular,Angular,我是新手。 我想在ng模板中处理组件(验证警报) <ng-template #content let-c="close" let-d="dismiss" size="600px" > <validation-alerts [formGroup]="requestTypeForm"></validation-alerts> <div class="ui-dialog-titlebar ui-widget-header ui-cor
<ng-template #content let-c="close" let-d="dismiss" size="600px" >
<validation-alerts [formGroup]="requestTypeForm"></validation-alerts>
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix head" tabindex="-1">
<span id="ui-id-6" class="ui-dialog-title popup-title">Client Name Look Up </span>
<button (click)="d('Cross click')" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close"
role="button" aria-disabled="false" title="Close">
<span class="ui-button-icon-primary ui-icon ui-icon-closethick popup-close-icon"></span><span class="ui-button-text">Close</span>
</button>
</div>
<form (ngSubmit)="onSubmit()" [formGroup]="requestTypeForm">
<div id="scrollContainer-popup" class="popup ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; max-height: none; height: auto; display: block; padding: 0px 10px 0px">
<div class="body">
<p class="mb"><b>Select the matching client name:</b></p>
<input type="text" formControlName="clientId" name="clientId"
id="clientId" style="width:30%" />
<div class="btnBar nbdr" style="padding-top: 0px;" >
<a (click)="c('close')" class="btn3"><span>Cancel</span></a>
<button type="button" class="btn" (click)="c('submit')">Select</button>
</div>
</div>
</div>
</form>
</ng-template>
组件类
@Component({
selector: 'provision-modal',
templateUrl: 'provision.modal.html',
encapsulation: ViewEncapsulation.None,
styles : [ '.namelookup .modal-content { width: 600px;}']
})
export class ProvisionModal implements AfterContentInit {
@ViewChild('content') contentTemplate: TemplateRef<any>;
@ViewChild(ValidationAlertsComponent)
private validationAlerts: ValidationAlertsComponent;
ngAfterContentInit() {
console.log('Ng after content init '+ this.validationAlerts);
}
@组件({
选择器:'设置模式',
templateUrl:'provision.modal.html',
封装:视图封装。无,
样式:['.namelookup.modal内容{宽度:600px;}']
})
导出类ProvisionModal实现AfterContentInit{
@ViewChild(“内容”)内容模板:TemplateRef;
@ViewChild(ValidationUsersComponent)
私有validationerts:validationerts组件;
ngAfterContentInit(){
log('content init'之后的Ng+this.validationerts);
}
您应该在ngAfterViewInit生命周期挂钩之后访问视图子级
看
所以改变
ngAfterContentInit() {
console.log('Ng after content init '+ this.validationAlerts);
}
到
请发布更多的组件类代码组件类代码AddedValidationErts未定义是否已在临时模态组件中导入ValidationErts组件?是的,我已导入ValidationErts
ngAfterContentInit() {
console.log('Ng after content init '+ this.validationAlerts);
}
ngAfterViewInit() {
}