Search code examples
javascriptangularjsformsangular-formly

passing formly values from child to parent component in angularJS


Been having trouble passing values from a formly form in a child component to pass to a parent.

so i have this formly field in a review.controller.js (child)

$scope.fields = [
        {
          className: "row",
          fieldGroup: [
            {
              fieldGroup: [
                {
                  key: 'firstName',
                  type: 'horizontalInput',
                  name: 'First Name',
                  templateOptions: {
                    label: 'First Name',
                    type: 'text',
                    required: true,
                  },
                }
              ]
            }
          ]
        }

that i want to pass to a submit.controller.js (parent)

    $scope.submitApplication = function() {
            var firstname = $scope.$parent.fields.guestFirstName;
            }
          };

I tried using the $scope.$parent to retrieve the values but its not really working...any input would be greatly appreciated!


Solution

  • It's not really clear what you are asking. The values are all contained in the model, no matter how many fieldGroups they are inside of.

    You should be able to simply use:

    var firstname = $scope.fields.guestFirstName;