0

我的组件代码:

(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);

}());

模板 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>

问题:据我所知 $ctrl.email 应该是双向绑定变量。但是每当我提交表单时,我都会变得不确定。在代码中 ctrl.email 未定义。

谁能解释一下我在这方面做错了什么?

4

1 回答 1

1

有错别字,应该是

ng-model="$ctrl.email"

代替ng-modal

于 2017-10-14T13:54:04.667 回答