我在提交表單時遇到了模態表單值問題。日誌說addMountForm是未定義的。我提供了我的html代碼片段以及組件。我很感謝你的幫助。Angular 4從模態獲取表格值
<ng-template #content let-c="close" let-d="dismiss">
<div class="modal-header">
<h3 class="modal-title">Add Mount Point</h3>
</div>
<div class="modal-body">
<form (ngSubmit)="onSubmit()" #addMountForm="ngForm" >
<div class="form-group">
<label class="col-sm-2 control-label text-nowrap"
for="archiveOrigin">Archive Origin</label>
<div class="col-sm-10">
<input type="text" class="form-control" ngModel id="archiveOrigin" name="archiveOrigin" placeholder="Archive Origin"/>
</div>
</div>
<button type="submit" class="btn btn-default">Add</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" (click)="c('Close click')">
Close
</button>
</div>
</ng-template>
<div class="page pt-2">
</div>
@Component({
selector: 'mount-point',
templateUrl: './mountpoint.component.html',
styleUrls: ['./mountpoint.component.scss']
})
export class MountPointComponent implements OnInit {
@ViewChild('addMountForm') addMountForm : NgForm;
constructor(
private modalService: NgbModal
){}
open(content) {
this.modalService.open(content).result.then((result) => {
console.log("closed");
}, (reason) => {
console.log("dismissed");
});
}
onSubmit(){
console.log("adding form values ");
console.log(this.addMountForm);
}
}
當您提交表單時模式彈出關閉還是仍然打開? –
你使用什麼版本的模態?這個? https://github.com/shlomiassaf/angular2-modal – JGFMK