简体   繁体   中英

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!

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM