Reputation: 2496
I use angular and angular-material for design so i can push item to array but not update in view
My code :
ClientService.saveClient(client).$promise.then(
function(data) {
items.data.push(data);
},function (data) {
console.log(data);
});
and in $mdDialog.show my code :
$scope.addClient = function (event) {
$mdDialog.show({
controller: DialogController,
locals: {
items: $scope.clients
},
parent: angular.element(document.body),
templateUrl: 'views/client/addclient.html',
controllerAs: 'ctrl',
clickOutsideToClose:true,
targetEvent: event
}).then(function (add) {
init();
console.log($scope.clients);
}, function(cancel) {
});
};
In console log the client added with success but not update in table .
ps init function :
var init = function () {
ClientService.getClients().$promise.then(function (data) {
$scope.clients = {
"count":data.length,
"data":data
};
});
};
So how can i get client after added ? and thanks .
Upvotes: 0
Views: 99
Reputation: 222592
Try this,
ClientService.getClients().$promise.then(function (data) {
$scope.clients = {
"count":data.length,
"data":data
};
$scope.$apply();
});
Upvotes: 1