Мне кажется, что я пропустил здесь что-то простое, но это меня озадачило.Angular - Form wont submit
Почему ничего не происходит, когда я нажимаю кнопку отправки?
<section ng-controller="SavingsController as savingsCTRL">
<form name="createSavingForm" class="form-horizontal" novalidate>
<fieldset>
<!-- Title Box Start-->
<div class="form-group new-deal-form" show-errors>
<label for="title">Title</label>
<input name="title" type="text" ng-model="savingsCTRL.title" id="title" class="form-control" placeholder="Title" required>
<div class="sub-label">Enter the Title of the Deal.</div>
<div ng-messages="savingForm.savingsCTRL.title.$error" role="alert">
<p class="help-block error-text" ng-message="required">Saving title is required.</p>
</div>
</div>
<!-- Title Box End-->
<!--Submit Button Start-->
<div class="form-group buttons-cancel-submit">
<button class="btn btn-default " ng-click="savingsCTRL.cancel()">Cancel</button>
<input type="submit" class="btn btn-success " ng-click="savingsCTRL.create(); submitForm(createSavingForm.$valid)" >
</div>
</fieldset>
</form>
</div>
</div>
</section>
Для простоты я взял большую часть форм, но что еще не так?
Экономия Контроллер Функция
// Create new Saving
$scope.create = function() {
$scope.error = null;
alert("create");
// Create new Saving object
var saving = new Savings({
title: this.title,
details: this.details,
retailer: this.retailer,
price: this.price,
link: this.link,
image: $scope.user.imageURL,
urlimage: this.urlimage,
tags: this.tags
//startdate: this.startdate,
//enddate: this.enddate
});
// Redirect after save
saving.$save(function (response) {
$location.path('savings/' + response._id);
// Clear form fields
$scope.title = '';
$scope.details = '';
$scope.retailer = '';
$scope.price = '';
$scope.link = '';
$scope.image = '';
$scope.urlimage = '';
$scope.tags = '';
}, function (errorResponse) {
$scope.error = errorResponse.data.message;
});
};
Живой пример был бы лучше. Чтобы использовать отправку таким образом, вы должны определить действие в своей форме. Или измените тип ввода на кнопку и получите информацию о форме на контроллере. –
Слишком много информации отсутствует. Где javascript? Где контроллер определен? –
Где ваш контроллер привязан к вашему шаблону? Если вы не используете выделенные области, вам нужно использовать 'ng-controller' в вашем html, также где метод submitForm объявлен, что он, похоже, не связан с контроллером, как ваши другие методы: – br3w5