Wednesday, 15 April 2015

angularjs - Angular : how refresh list after modal use? -



angularjs - Angular : how refresh list after modal use? -

i have employee list (ng-repeat), can update employee info modal. when click on save button, list not updated (i must press f5).

i seek utilize $watch without succes

there controllers (list , modal) :

var employee = angular.module('employee.module', [ 'app.common.module', 'employee.services', 'employee.router', 'ui.bootstrap' ]); employee.controller('employeectrl', [ '$scope', '$log', 'employeeservices', employeectrl ]); function employeectrl($scope, $log, employeeservices) { $scope.retrieveemp = function(){ // retrieve employee list --> ok homecoming $scope.lesemployees = employeeservices.getemployees(); } // $scope.$watch('retrieveemp'); $scope.retrieveemp(); $scope.$watch($scope.lesemployees); /*...*/ } /* modal controller update or visu */ employee.controller('modalctrl', [ '$scope', '$log', 'employeeservices', '$stateparams', modalctrl ]); function modalctrl ($scope, $log, employeeservices, $stateparams) { // display infos in modal --> ok employeeservices.getdetail($stateparams.id).$getpromise().then( function(detailemp) { $scope.detailemployee = detailemp; }, function() { $scope.detailemployee = []; $scope.totalitems = 0; } ); // close button $scope.close = function() { $scope.$close(true); }; // update button $scope.ok = function(){ employeeservices.updateemp($scope.detailemployee).$getpromise().then( $scope.close() ) }; }; })();

i don't understand how utilize $watch, don't find illustration using modal. in controller must utilize $watch ?

or simply, $watch right way ?

thank's in advance

i didn't find problem find way update list !

function modalctrl ($scope, $log, employeeservices, $stateparams, $rootscope ) { // detail employeeservices.getdetail($stateparams.id).$getpromise().then( function(detailemp) { $log.info("retrieve liste, date = " + detailemp.hiredate); $scope.detailemployee = detailemp; } ); // close modal $scope.close = function() { $scope.$close(true); }; // update list var updateemployees = function (item) { (var = 0; < $rootscope.lesemployees.length; ++i) { if ($rootscope.lesemployees[i].idemployee === item.idemployee) { $rootscope.lesemployees[i] = item; break; } } } $scope.ok = function(){ employeeservices.updateemp($scope.detailemployee).$getpromise().then( function(updateitem) { // updateitem boolean // true -> update ok // false -> update ko updateemployees($scope.detailemployee); } ); $scope.close(); }; };

it works fine !!

angularjs angularjs-scope angularjs-ng-repeat

No comments:

Post a Comment