我有一種表單,我想傳遞一些數據並將它們發佈到URL中。 我在這裏做錯了什麼?由於無法將數據從模板傳遞到控制器angularjs
template.html
<div ng-controller="statusController">
<form role="form" name="form" method="post" ng-submit="rate(ratingData)">
<div class="form-group float-label-control">
<label for="title">Title</label>
<input id="title" name="title" type="text" class="form-control" placeholder="Title" ng-model="ratingData.title">
</div>
<div class="form-group float-label-control">
<label for="rating">Rating</label>
<input id="rating" name="rating" type="text" class="form-control" placeholder="Rating" ng-model="ratingData.rating">
</div>
<div class="form-group float-label-control">
<label for="review">Review</label>
<input id="review" name="review" type="text" class="form-control" placeholder="Review" required ng-model="ratingData.review">
</div>
<div class="form-group float-label-control text-center ">
<button type="submit" class="btn btn-primary" formmethod="post">Submit</button>
</div>
</form>
controller.js
angular.module('deliveryStatus', ['ngRoute'])
.component('deliveryStatus', {
templateUrl: 'components/delivery-status/delivery-status.template.html'
})
.controller('statusController', function ($http, $scope, $routeParams, Auth, $window, $timeout, $location) {
$scope.rate = function (ratingData) {
$location.url('/rating');
$http.put('/api/rating-detail', $scope.ratingData).then(function (res) {
console.log('worked');
}).catch(function (err) {
console.log('error rating');
});
};
});
這看起來很愚蠢,但是控制器也被命名爲'statusController'? –
@DanielD是控制器被命名爲'statusController',但我沒有粘貼全部 – XhensB
你可以添加整個控制器代碼嗎? –