將數據發送到我的控制器時出現問題。這是我的看法無法從輸入角度看控制器中的數字
<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>
,這是我的控制,我在那裏我的數據發送到:
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);
}
};
});
我有一個的console.log()在控制器中可以查看正在發送的是什麼數據和只有文本被髮送。我試圖將前兩個輸入隱藏起來,並在其中有價值。它基本上是向線程發送評論,所以它包含線程的用戶和標識的id。我不希望它們可見,但我需要將它們發送給控制器。當我輸入的數字manualy,它工作正常,但是當我有它的價值=「」屬性,我得到這個錯誤控制檯:
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+)?
我不明白,因爲當我打開開發工具並看看它的價值,它就像一個數字。而當
好的,所以我刪除了值屬性。然後在發送文本值時,我在控制器本身中添加了所需的id。我在localStorage中有用戶標識,線程標識在URL中 – Arcane