我想使用输入文本向我的数据库添加新评论,但我不想使用表单或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