none
How to get promise result from Sharepoint API using AngularJS RRS feed

  • Question

  • The following is the controller used to retrieve information from sharepoint. I can see debugging that the entry data.d.UserProfileProperties.results[115].Value has a property value that I need to render in view. How can I get that value from the result promise?

    (function() {
        'use strict'
        var createPurchasingCardController = function($scope, $rootScope, $filter, $window, $location, $timeout, requestService) {        

            $scope.actionTitle = "";
            $scope.counter = [];                      

            var getCurrentUserData = function () {

                var dfd = new $.Deferred();
                var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties";
                $.ajax({
                    url: queryUrl,
                    method: "GET",
                    headers: { "Accept": "application/json; odata=verbose" },
                    success: onSuccess,
                    error: onError,
                    cache: false
                });

                function onSuccess(data) {            
                    dfd.resolve(data);                    
                }

                function onError(data, errorCode, errorMessage) {
                    dfd.reject(errorMessage);
                }

                return dfd.promise();               
            }            

            var _init = function () {                
                $scope.counter = getCurrentUserData();
                console.log($scope.counter);
            }

            _init();

        }

        angular.module('myApp').controller('createPurchasingCardController', ['$scope', '$rootScope', '$filter', '$window', '$location', '$timeout', 'requestService', createPurchasingCardController]);
    }());

    I have tried to get it into the counter but it is not showing up. Any help would be appreciated.


    Carlos M

    Friday, November 15, 2019 4:16 AM

Answers

  • Hi Carlos,

    We can get the data as below.

    $.each(data.d.UserProfileProperties.results,function(i,property){
    	console.log(property.Key+":"+property.Value);				
    });	

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Carlos MC Friday, November 15, 2019 5:04 PM
    Friday, November 15, 2019 8:22 AM
    Moderator