我想使用輸入文本向我的數據庫添加新評論,但我不想使用表單或onclick。這裏是我輸入的文本結構使用輸入按鈕將數據插入數據庫
<input type="text" class="comment_input" ng-model="comment" ng-model-options="{updateOn : 'change blur'}" placeholder="To enter" />
當我嘗試使用綁定,它表明我的意見時,我按回車鍵,但我想它插入到我的數據庫API ..這裏的是我在插入數據功能。
$scope.insertData=function(){
console.log($scope.comment);
console.log($scope.lang_code);
console.log($scope.user_id);
console.log($scope.product_id);
var dataPromise = Data.setData("API_URL","user_id="+$scope.user_id+"&product_id="+$scope.product_id+"&comment="+$scope.comment+"&lang="+$scope.lang_code);
dataPromise.then(function(greeting) {
console.log(greeting);
if (greeting.data.result == true) {
$scope.requestProductDetail(1,5,1);
$timeout(function() {
window.scrollTo(0,document.body.scrollHeight);
}, 0, false);
}
}, function(reason) {
}, function(update) {
});
}}]);
有人嗎?
啊,以及如何刷新本頁後我做了什麼? * insertdata /的onclick按鈕
你可以使用NG-按鍵指令HTTPS調用$ window.location.reload()://docs.angularjs。 org/api/ng/directive/ngKeypress – talentedandrew