如何在提交角度5上从ngx-modal检索数据

时间:2018-06-12 09:56:41

标签: angular typescript angular-material angular5 ngx-modal

我使用ngx-modal创建对话框,下面是html中的代码

<button (click)="myModal.open()">Click Me</button>

<modal #myModal cancelButtonLabel="Cancel All 
[(ngModel)]="rfin" submitButtonLabel="submit" 
(onSubmit)="callSubmit()">

<modal-content >
<mat-card>
<mat-card-content   >
<h2 class="example-h2">Select Emp</h2><br>

<section class="example-section" *ngFor="let ep of emp" >

<ng-template>
<mat-checkbox [(ngModel)]="ep.checked">{{ep.name}}</mat-checkbox>
</ng-template>

</section>

</mat-card>
</modal-content>
</modal>

这是我的ts文件中的代码

callSubmit(val)
{
Console.log(val);
}

但我没有定义。 请建议

添加了组件代码,这里我试图在控制台中访问数据。

    import { Component,  Input, OnInit, Inject } from '@angular/core';
    import { ConfigService } from '../services/config.service';
    import { FormControl } from '@angular/forms';

    @Component({
    selector: 'app-emp,
    templateUrl: './emp.html',
    styleUrls: ['./emp.css'],
    })
    export class EmpComponent {
    rfin:any;
    empdata:any=[];
    emp:any=[];

    constructor(private configs: ConfigService){}

    callSubmit() 
    {
    Console.log(this.rfin);
    }

// getEmp是一个服务调用,用于从api获取值     getEmp(){

this.configs.doEmp().subscribe(

data => {this.empdata = data['emp'];

this.emp = this.empdata.map(o => {
return {

name: o.name, isData: o.isData, checked: false

};

});

},

err => console.error(err),         
() => console.log('done loading emp'));

}

 ngOnInit() {
        this.getEmp();
    }
}

更新了提交也

1 个答案:

答案 0 :(得分:0)

我不确定您在模型弹出部分中使用tokencustomset的原因。但是你可以尝试这种替代方式来读/写模型对象。

您不需要将模型对象传递给[(ngModel)]="rfin"方法。你可以直接在方法本身中使用。

onSubmit

代码

(onSubmit)="callSubmit()"

注意:请确保您在组件类中声明此模型callSubmit() { Console.log(this.rfin); } 对象