Two-way data binding, null values

Discussão em 'Angular' iniciado por HAC, Março 27, 2025.

  1. HAC

    HAC Guest

    I am having an issue with two way data binding and Angular 8

    In the following example, my model (service.formData) is populated, but one of the variables (which is really a child table) is null (service.formData.ProjectSshaspModel). If I populate data in the database, the two way binding seems to work ok and retrieves and passes data back. But when the variable is null when the page loads, and I populate the model (HTML page), the object does not seem to get populated

    I have placed both the HMTL, Angular data binding and JSON values below.

    <form #form="ngForm" autocomplete="off" (submit)="OnSubmit(form)" *ngIf="service.formData">
    <div class="row" id="section1">
    <div class="col-md-10">

    <input type="hidden" name="ProjectID" #ProjectID="ngModel" [(ngModel)]="service.formData.ProjectID" />
    <input type="hidden" name="ProjectSshaspModel.ProjectSshaspID" #ProjectSshaspModel.ProjectSshaspID="ngModel" [(ngModel)]="service.formData.ProjectSshaspModel.ProjectSshaspID" />
    <input type="radio" id="not-required"
    name="CompanyLogoRequired" #ProjectSshaspModel.CompanyLogoRequired="ngModel" [(ngModel)]="service.formData.ProjectSshaspModel && service.formData.ProjectSshaspModel.CompanyLogoRequired" ng-checked="(CompanyLogoRequired==0)" [value]="0" />
    Not Required
    &nbsp;
    <input type="radio" id="incorporate"
    name="CompanyLogoRequired" #ProjectSshaspModel.CompanyLogoRequired="ngModel" [(ngModel)]="service.formData.ProjectSshaspModel && service.formData.ProjectSshaspModel.CompanyLogoRequired" ng-checked="(CompanyLogoRequired==1)" [value]="1" />
    Incorporate


    {
    "projectModel": {
    "ProjectSshaspModel": null,
    "ProjectID": "a9400d92-de37-4c00-957e-08d7bbd4b4c5",
    "ProjectNumber": "2020-1233",
    "Consultant": "Joe Test",
    "AssignedDate": "2020-02-28T00:00:00",
    "ClientDueDate": "2020-02-29T00:00:00",
    "ProjectCreationDate": "2020-02-28T00:00:00",
    "ScopeOfWork": "Scope of work",
    "Service": 0,
    "ClientName": "Ebay",
    "CompanyContact": "John Smith",
    "CompanyContactPhone": "555-555-5555",
    "CompanyContactEmail": "jsmith@comcast.net",
    "CompanyAddress": "123 Sesame Place Test, JN 01111",
    "CompanyType": 2
    }
    }

    Continue reading...

Compartilhe esta Página