3
正如我在標題中提到的那樣,我只是想在POST後的另一個控制器中更新數據,這裏是我的代碼。Angular在POST後重新載入另一個控制器
將數據保存到數據庫沒有問題。
腳本
var app = angular.module('userBase', []);
app.controller('listUsers', function($scope,$http) {
$http.get("req.php")
.then(function (response) {
$scope.userloop = response.data.reqresponse;
});
});
app.controller('addUsers', function($scope,$http) {
$scope.buttonFire = function() {
$http.post("add.php",{'name': $scope.name, 'email': $scope.email})
.success(function(data, status, headers, config){
});
}
});
查看
<div ng-controller="listUsers">
<ul ng-repeat="x in userloop">
<li>{{ x.Name }} - {{ x.Email }} </li>
</ul>
</div>
<div ng-controller="addUsers">
<p>Name: <input type="text" ng-model="name"></p>
<p>Email: <input type="text" ng-model="email"></p>
<span ng-bind="name"></span> and <span ng-bind="email"></span><br/>
<button ng-click="buttonFire()">Send or Save</button>
</div>
非常感謝你這有助於中號e :) – Jerushan