Having an issue with sending data to the controller via my view. Below is a snippet of the code:
<form ng-submit="submitMessage()">
<div class="form-group">
<input type="number" class="form-control input-sm" name="id_user" ng-model="messageData.id_user" value={{currentUser.id}} >
</div>
<div class="form-group">
<input type="number" class="form-control input-sm" name="id_thread" ng-model="messageData.id_thread" value={{messages[0].id_thread}}>
</div>
<!-- COMMENT TEXT -->
<div class="form-group">
<input type="text" class="form-control input-lg" name="message" ng-model="messageData.text" placeholder="Write your message">
</div>
<!-- SUBMIT BUTTON -->
<div class="form-group text-right">
<button type="submit" class="btn btn-primary btn-lg submit-btn">Submit</button>
</div>
</form>
For handling this in my controller:
angular.module('messageCtrl', []).controller('messageController', function($scope, $http, Message, $stateParams) {
// object to hold all the data for the new comment form
$scope.messageData = {};
//get id from route
var id = $stateParams.id;
// get all the comments first and bind it to the $scope.comments object
// use the function we created in our service
// GET ALL COMMENTS ==================================================
Message.get(id).then(successCallback);
function successCallback(data) {
$scope.messages = data.data;
}
// function to handle submitting the form
// SAVE A COMMENT =====================================================
$scope.submitMessage = function() {
// save the comment. pass in comment data from the form
// use the function we created in our service
console.log($scope.messageData);
Message.save($scope.messageData).then(successCallback2, errorCallback);
function successCallback2(getData) {
$scope.messages = getData.data;
Message.get(id).then(successCallback);
}
function errorCallback(data) {
console.log(data);
}
};
});
Encountering issues whereby only the 'text' field is sent to the controller when attempting to send data. The aim is to have the two initial inputs hidden but still contain predefined values. However, including these values within the "value" attribute leads to errors as follows:
angular.js:3505 The specified value "{{messages[0]['id_thread']}}" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?
angular.js:3505 The specified value "{{currentUser.id}}" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?
The puzzling aspect here is that upon inspecting the values in the developer tools, they are numerical. Any insights on how to resolve this dilemma would be greatly appreciated.