0

How can I get global navigation into my angularApp using $httpget method in angularJs.

Does sharepoint store global navigation in any List? Then I can get it by using $http get method.

I tried @gautam's answer/code but it's didn't work for me, I got following data

[{
  "CustomProperties": {
    "__metadata": {
      "type": "Collection(SP.KeyValue)"
    },
    "results": []
  },
  "FriendlyUrlSegment": "test-1",
  "IsDeleted": false,
  "IsHidden": false,
  "Key": "2e0787a2-773d-418f-90e1-03a903c08563",
  "Nodes": "__metadata": {
    "type": "Collection(SP.MenuNode)"
  },
  "results": []
  },
  "NodeType": 1,
  "SimpleUrl": "",
  "Title": "Test 1"
}]
2

1 Answer 1

2

You can get the global navigation in angular like below:

var myAngApp = angular.module('SharePointAngApp', []);  
myAngApp.controller('spController', function ($scope, $http) {  
    $http({  
        method: 'GET',  
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/navigation/menustate?mapprovidername='GlobalNavigationSwitchableProvider'",  
        headers: { "Accept": "application/json;odata=verbose" }  
    }).success(function (data, status, headers, config) {  
        $scope.results = data.d.MenuState.Nodes.results;  
    }).error(function (data, status, headers, config) {  

    });  
});   
4
  • 2
    example for the Angular View for the code above: <ul ng-repeat='nav in results'><li> <a ng-href='{{nav.SimpleUrl}}'>{{nav.Title}}</a> </li></ul> Oct 12, 2016 at 14:29
  • Tried your code but didn't get navigation links Oct 13, 2016 at 5:34
  • @gautam I have updated my Question, Please take a look.. Oct 13, 2016 at 6:03
  • Your code worked when I updated 'GlobalNavigationSwitchableProvider' to 'GlobalNavigation'. Oct 13, 2016 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.