ng-submit不以形式工作

时间:2016-01-17 20:25:03

标签: javascript html angularjs frontend mean-stack

我已经审核了有关ng-submit的所有问题,但我仍然无法让它发挥作用。在提交时,它应该调用post控制器中的publish()函数。为了在SO上共享它,我只在函数中包含了console.log()。但是,我在下方有另一个按钮,单击此按钮将调用发布功能并将控制台登录到Chrome控制台。

post.html

<form ng-submit="post.publish()">
  <div class="form-input-body">
    <textarea ng-model="post.postData.body"></textarea>
  </div>
  <button type="submit">Publish</button> // This doesn't call the function
</form>
<button type ng-click="post.publish()"> // This calls the function

postController.js

angular.module('postCreateCtrl', ['postCreateService'])
    .controller('postCreateController', function(PostCreate) {
        var vm = this;

        vm.publish = function() {
            console.log("This doesn't work");
        };

    });

app.js(我已经编辑了一些代码)

angular.module('myApp',

[
    ...

    'postCreateController',
    'postCreateService'
]);

app.routes.js

angular.module('app.routes', ['ui.router'])
  .config(function($stateProvider, $urlRouterProvider, $locationProvider) {
    $urlRouterProvider.otherwise('/');

    $stateProvider
      ...

      .state('postCreate', {
        url: '/posts/create',
        templateUrl: 'app/components/postCreate/post.html',
        controller: 'postCreateController',
        controllerAs: 'post'
      });

      $locationProvider.html5Mode(true);
  });

0 个答案:

没有答案