Here is my html form in laravel application which has hidden fields, these hidden values need to send to the angular js controller.
<form accept-charset="UTF-8" enctype="multipart/form-data">
<input name="_token" type="hidden" value="{{ csrf_token() }}">
<input name="user_id" type="hidden" value="{{ Auth::user()->id }}">
<input name="post_id" type="hidden" value="<% post.id %>" >
<input name="published_at" type="hidden" value="{{ Carbon\Carbon::today()->format('Y-m-d') }}">
<input class="form-control" placeholder="comment" ng-model="contentField" type="text" >
<button type="submit" ng-click="addComment()">comment</button>
</form>
My Angular Controller is as follows
$scope.addComment = function(){
var comment = {
user_id: $scope.user_id,
content: $scope.contentField,
post_id: $scope.post_id,
published_at: $scope.published_at
};
I am only getting the value of contentField in the controller, Please Help me to solve this problem !
It seems that you are missing the ng-model
tags on your hidden imports. Because of that angular does not know how or where to bind the hidden input values to the $scope
. Adding those tags to all of the hidden inputs should fix your issue of them not being found on the $scope
.