0

My component code:

(function () {
  'use strict';

  function SubscribeController(toaster, EmbHTTPFactory) {
    var ctrl = this;

    ctrl.submit = function () {
      EmbHTTPFactory.subscribeToNewsletter(ctrl.email).then(function (res) {
        toaster.pop('success', "User successfully subscribed");
      },function (err) {

      });
    }
  }

  var app = angular.module('24hourdigitizing'),
      config = {
        templateUrl: "app/views/components/form-component.html",
        controller: ['toaster', 'ng24hdDigitizing.factories.EmbHTTPFactory', SubscribeController],
        bindings: {
          label: '<',
          button: '<',
          action: '<',
          classname: '<'
        }
      };

  app.component('formComponent', config);

}());

Template HTML

<div class="container">
        <div class="row">
            <form action="" name="formElement" class="form-element">
                <div class="form-group no-margin">
                    <label for="email" ng-if="$ctrl.label">{{ $ctrl.label }}</label>
                    <div class="">
                        <input class="form-control input-lg"
                               type="text"
                               id="email"
                               name="email"
                               ng-modal="$ctrl.email"
                               placeholder="Email..."
                               ng-required="true"
                        >
                    </div>
                    <button
                            type="button"
                            class="btn btn-primary btn-lg"
                            ng-disabled="formElement.$invalid"
                            ng-click="$ctrl.submit()"
                    >{{ $ctrl.button }}</button>
                </div>
            </form>
        </div>
    </div>

Issue: As far as I know the $ctrl.email should be a two way binded variable. But whenever I submit the form I am getting undefined. In the code ctrl.email is undefined.

Can anyone please explain if I am doing something wrong on this?

1 Answer 1

1

There is typo, it should be

ng-model="$ctrl.email"

instead of ng-modal

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.