Private/Angular/Component/Crud/New-NgCrudComponentHtmlToString.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Function New-NgCrudComponentHtmlToString([WebCsprojInfo]$webCsprojInfo, [TableInfo]$tableInfo)
{
    [string]$result = @"
<div *ngIf="$($tableInfo.tableLowerCamel)">
  <h2>$($tableInfo.tablePretty)</h2>

  <form [formGroup]="$($tableInfo.tableLowerCamel)Form" (ngSubmit)="save()">
"@


    foreach ($columnInfo in $tableInfo.columnInfos)
    {
        $result = $result + @"
            <div class="form-group">
              <label for="name">{{formMetaData.$($columnInfo.columnLowerCamel).caption}}</label>
              <input type="text" id="$($columnInfo.columnLowerCamel)" class="form-control" formControlName="$($columnInfo.columnLowerCamel)" [ngStyle]="formMetaData.$($columnInfo.columnLowerCamel).style" [attr.maxlength]="formMetaData.$($columnInfo.columnLowerCamel).maxlength">
              <div *ngIf="formErrors.$($columnInfo.columnLowerCamel)" class="alert alert-danger">
                {{ formErrors.$($columnInfo.columnLowerCamel)}}
              </div>
            </div>
"@

    }

    $result = $result + @"
    <button type="submit" class="btn btn-default" [disabled]="!$($tableInfo.tableLowerCamel)Form.valid" >Save</button>
    <button class="btn btn-secondary" (click)="goBack()">Back</button>
    <button class="btn btn-danger" (click)="delete()">Delete</button>
  </form>
</div>
"@


    return $result 
}