小编Moh*_*wal的帖子

访问 FormArray 内 FormGroup 中的 FormControl

我正在尝试在 formarray 中的 formcontrol 上实现材料自动更正,但是当我尝试访问 ts 文件中的 formcontrol 时,它无法访问它。谁能帮帮我吗。

html 文件:

<div formArrayName="applicants">
          <div *ngFor="let applicant of appForm.controls.applicants.controls; let i=index; let last = last">
            <div [formGroupName]="i">
              <div class="row">
                <label for="applicant_short_name" class="col-sm-3 form-control-label">Applicant {{i+1}}</label>
                <div class="col-sm-7">
                  <div class="form-group">
                    <!-- <input type="text" formControlName="applicant_short_name" class="form-control" id="inputFirstName" placeholder="Applicant"> -->
                    <!-- <mat-form-field > -->
                      <input  type="text" class="form-control" id="inputFirstName" placeholder="Applicant" [matAutocomplete]="auto" [formControlName]="applicant_short_name">
                      <mat-autocomplete #auto="matAutocomplete">
                        <mat-option *ngFor="let state of filteredNames | async | slice:0:3" [value]="name">
                          <span>{{ name }}</span>
                        </mat-option>
                      </mat-autocomplete>
                    <!-- </mat-form-field> -->
                  </div>
                </div>
Run Code Online (Sandbox Code Playgroud)

.ts 文件: …

form-control angular-material angular

5
推荐指数
1
解决办法
6338
查看次数

为什么.catch在执行者完成任务之前就被执行了?

运行下面的代码后,我已经提到了我在控制台中得到的输出.根据我的理解,一旦定义了promise,执行者就完成了它的任务,然后只有.catch执行.但是下面的结果表明.catch在执行程序运行之前执行.有人可以帮忙吗?

码:

var dbconnect = new Promise(function(resolve, reject){
    mongoClient.connect(db, { useNewUrlParser: true }, (error, db) => {
        if (error) {
            console.log('Database connection failed')
            reject(Error('Database Connection Failed'))
        } else {
            console.log('Database connected')
            resolve(db)
        }
    })
});

dbconnect
.then(
    db => {
         console.log('db value :', db);
    },
    error => {
        console.log('connection failed :', error)
    }
)
.catch(
    console.log('exception handling')
); 
Run Code Online (Sandbox Code Playgroud)

输出:异常处理

数据库连接

db值:MongoClient {domain:null,

node.js promise

0
推荐指数
1
解决办法
23
查看次数