当我在angularjs中插入表单时,在数据库中插入我的数据后。我的记录不显示,直到重新加载页面。
其My Js控制器: -
$scope.mywarehousess = [];
$http({
url:'warehouse/warehouse_fetchdata',
method: "POST"
}).success(function (data) {
$scope.mywarehousess = data;
});
HTLM查看或列出页面代码: -
<tr>
<th>SL. NO.</th>
<th>Warehouse Name</th>
<th>Warehouse Address</th>
<th>Manage</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="warehouse in mywarehousess">
<td>{{$index +1}}</td>
<!--<td>{{warehouse.warehouse_key}}</td>-->
<td>{{warehouse.warehouse_name}}</td>
<td>{{warehouse.warehouse_address}}</td>
<td>
<a data-toggle="modal" data-target="#update" ng-click="getEditWarehousedata(warehouse.warehouse_id)" class="table-action-btn"
style="cursor:pointer;"><i class="md md-edit"></i></a>
<a data-toggle="modal" data-target="#del" ng-click="getEditWarehousedata(warehouse.warehouse_id)" class="table-action-btn"><i class="md md-delete"></i></a>
</td>
</tr>
</tbody>
Codeigniter控制器: -
public function warehouse_fetchdata(){
$result = $this->user_model->select_all_warehouse(['warehouse_status'=>1]);
//print_r($result);
echo json_encode($result);
}
添加js控制器: -
$ scope.form = {};
$scope.savewarehouse = function () {
$http({
method: 'post',
url: 'warehouse/insert_warehouse',
data: $scope.form,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data)
{
});
};
答案 0 :(得分:0)
添加后,您需要更新$scope
变量
因此,在您的成功回复中,$scope.mywarehousess.push($scope.form)
$scope.savewarehouse = function () {
$http({
method: 'post',
url: 'warehouse/insert_warehouse',
data: $scope.form,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data)
{
$scope.mywarehousess.push($scope.form)
});
};