[英]Pass php variable to angular
I'm using angular to add comments to a list. 我正在使用angular来为列表添加注释。 This is working fine.
这工作正常。 But I'm stuck with adding a php variable to save this to my list.
但我坚持添加一个php变量来保存到我的列表中。
HTML: 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 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. 我希望“ID”也保存在我的mysql中。 But I dont get it to work.
但是我不能让它发挥作用。
EDIT: I've got it to work. 编辑:我有它工作。 Code was ok, but my addCustomerComment.php was not.
代码还可以,但我的addCustomerComment.php却没有。 But another problem occurs.
但另一个问题出现了。 When opening the page the ID is not passed onto the angular.
打开页面时,ID不会传递到角度。 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.
因此,新注释会添加到正确的ID中,但较旧的注释仅在添加新注释后才可见。 How can I get the ID in angular when the page loads?
如何在页面加载时以角度获取ID?
JS: 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;
});
};
Try to post your data like this 尝试发布您的数据
$scope.createBook = function(book_form,user){
if(book_form.$invalid) {
$scope.invalidSubmitAttempt = true;
return;
}else{
$http.post(appurl+'user/adds/', user).success(function() {
});
$scope.book_form.$setPristine();
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.