我有两个组件,一个顶部栏和图像组件
图片上传后图像上传工作正常我正在调用此函数中的函数onUploadSuccess当我尝试使用新上传的图像重置它时显示错误无法设置未定义的属性'profileimagepath'
图片html
<img #profilepicdiv [src]="profileimagepath" width="48" height="48" alt="User" style="border-radius:100px" />
顶栏组件
@Component({
templateUrl: './topbar.component.html',
selector: 'top-bar',
encapsulation: ViewEncapsulation.None
})
export class TopBarComponent extends AppComponentBase {
@Input() profileimagepath: string = "/assets/images/user.png";
constructor(
injector: Injector,
private _authService: AppAuthService
) {
super(injector);
}
}
图像组件
import { TopBarComponent } from '@app/layout/topbar.component';
@Component({
selector: 'studentimage',
templateUrl: './studentimage.component.html'
})
export class StudentImageComponent extends AppComponentBase implements OnInit {
//@Input() multiple: boolean = false;
@ViewChild('fileInput') inputEl: ElementRef;
@ViewChild('topBarComponent') topBarComponent: TopBarComponent;
saving: boolean = false;
constructor(
injector: Injector, private http: Http,
private _studentService: StudentServiceServiceProxy
) {
super(injector);
}
ngOnInit(): void {
}
ngAfterViewInit(): void
{
alert('sdf');
}
onUploadSuccess() {
this.notify.success(this.l('Uploaded Successfully'));
this.topBarComponent.profileimagepath = /assets/images/newuser.png";
}
onUploadError() {
this.notify.error(this.l('Please try again'));
}
}
onloadupdate调用
<div [dropzone]="config" (error)="onUploadError($event)" (success)="onUploadSuccess($event)"></div>
尝试使用viewchild也是同样的问题