[英]Angular Material MatTableModule - How can I access the returned data from component.ts file from outside the mat-table in the template?
[英]How can I clear form data from another component using material dialog in the same ts file?
如何使用同一ts文件中的材質對話框從另一個組件清除表單數據?
這是我的.ts文件
@Component({
selector: 'clear-confirmation-dialog',
templateUrl: './clear-confirmation-dialog.html'
})
export class ClearConfimationDialog {
clearForm(){
/** FUNCTION TO CLEAR FORM DATA **/
}
}
@Component({
selector: 'app-enter-user',
templateUrl: './enter-user.component.html',
styleUrls: ['./enter-user.component.scss']
})
export class EnterUserComponent implements OnInit {
/** THIS IS THE FORM DATA **/
user = {
name: '',
address: ''
}
}
將EnterUserComponent
注入到ClearConfimationDialog
@Component({
selector: 'clear-confirmation-dialog',
templateUrl: './clear-confirmation-dialog.html'
})
export class ClearConfimationDialog {
enter_user_component:EnterUserComponent;
clearForm(){
/** FUNCTION TO CLEAR FORM DATA **/
this.enter_user_component.clearForm()
}
constructor(@Inject(forwardRef(() => EnterUserComponent)) enter_user_component:EnterUserComponent){
this.enter_user_component = enter_user_component
}
}
順便說一句,只有當app-enter-user
包括clear-confirmation-dialog
時,
例如:
enter-user.component.html:
....
<clear-confirmation-dialog></clear-confirmation-dialog>
....
您最好將@Optional()
和@Host()
裝飾器添加到enter_user_component
有關forwardRef的更多信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.