angularjs - How return `$resource` promise response? -
i require user details multiple areas. tried return details using generic function. getting result undefined. understand that, require use $differed reuslt. don't have idea current scenario.
anyone me here please?
here function:
$scope.currentuserinfo = function () { var userdetails; server.getprofile.get().$promise.then(function ( response ) { if( response.message.touppercase().indexof('success') != -1) { return userdetails = response; } return "not able user details time" }) return userdetails; } $scope.currentuser = $scope.currentuserinfo(); console.log( $scope.currentuser ) //undefined. var function1 = function () { $scope.currentuserinfo(); //once user details available further $scope.age = $scope.currentuser.age; } var function2 = function () { $scope.currentuserinfo(); //once user details available further $scope.name = $scope.currentuser.name; }
server.getprofile.get() asynchronous call. return userdetails; line in $scope.currentuserinfo function executed if server.getprofile.get() call not yet finish. try this:
$scope.currentuserinfo = function () { server.getprofile.get().$promise.then(function ( response ) { if( response.message.touppercase().indexof('success') != -1) { $scope.currentuser = response; } $scope.message = "not able user details time"; }) } $scope.currentuser populated after ajax call finish. assume using $scope.currentuser in html bindings when value changes automatically reflect in view
Comments
Post a Comment