I'm using angular to add comments to a list. This is working fine. But I'm stuck with adding a php variable to save this to my list.
HTML:
<div class="col-lg-6 col-md-12" ng-controller="customerCommentController" ng-init="userInit('<?php echo $_GET['id'] ?>')" >
<div class="box">
<div class="box-header">
<h3 class="box-title"><?php echo $lang['LBL_CUSTOMER_COMMENTS']; ?></h3>
</div><!-- /.box-header -->
<div class="box-body">
<div ng-include src="'php/layout_customer_comments.php'"</div>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div><!-- /.col -->
JS
var app = angular.module('customerCommentApp', []);
app.controller('customerCommentController', function($scope, $http) {
$scope.userInit = function(uid) {
$scope.user = uid;
};
getItem();
function getItem() {
$http.post("php/getCustomerComment.php").success(function(data){
$scope.items = data;
});
};
$scope.addItem = function (item) {
$http.post("php/addCustomerComment.php?item="+item+"&customerId="+$scope.user).success(function(data){
getItem();
$scope.itemInput = "";
});
};
});
I want the "ID" to be saved in my mysql as well. But I dont get it to work.
EDIT: I've got it to work. Code was ok, but my addCustomerComment.php was not. But another problem occurs. When opening the page the ID is not passed onto the angular. Only when I click the add button. So a new comment is added to the correct ID, but older comments are only visible after adding a new comment. How can I get the ID in angular when the page loads?
JS:
$scope.userInit = function(uid) {
$scope.user = uid;
//$scope.user = '99999';
};
// Load all available items
getItem();
function getItem(){
$http.post("php/getCustomerComment.php?customerId="+$scope.user).success(function(data){
$scope.items = data;
});
};