AngularJS记录不会显示在列表页面中,直到页面不刷新?



当我在angularJS中插入表单时,在数据库中插入我的数据之后。 在重新加载页面之前,我的记录不会显示。

它的我的Js控制器:-

$scope.mywarehousess = [];
$http({
url:'warehouse/warehouse_fetchdata',
method: "POST"
}).success(function (data) {
$scope.mywarehousess = data;
});

HTML 查看或列表页面代码:-

<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>

在此处输入图像描述

点火器控制器:-

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)
{
});
};

添加后需要更新$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)
});
};

最新更新