Repository navigation
ShareCoffee.REST.AngularJS
ShareCoffee works fine with Angular's $http in order to access data from SharePoint out of your SharePoint-Hosted App.
ShareCoffee is offering both, interaction with the AppWeb and interactions with the HostWeb. If you pass a HostWebUrl to any for.angularJS() call, ShareCoffee will create a configuration-object which allows HostWeb-Access.
Each of the following methods is configured by a single parameter of type ShareCoffee.REST.angularProperties. You can either create a new instance by using the constructor
ShareCoffee.REST.angularProperties() or you can pass a JSON object with corresponding properties.
/// Create property-object by using the constructor
var properties = new ShareCoffee.REST.RequestProperties(url, payload, hostWebUrl, eTag);
/// Create a property-object by using JSON syntax
var properties2 = { url: 'web/title')In order to create a configured properties object which can easily be passed to AngularJS' $http you just have to call ShareCoffee.REST.build.read.for.angularJS() and pass the REST endpoint you're looking for
$http(ShareCoffee.REST.build.read.for.angularJS({url:'web/lists?$select=Title,Id'}))
.success(function (data) {
$scope.lists = data.d.results;
})
.error(function (data, status) {
console.log(data);
console.log(status);
});description: TODO
var payload = {
'__metadata': { 'type': 'SP.List' },
'AllowContentTypes': true,
'BaseTemplate': 100,
'ContentTypesEnabled': true,
'Description': 'My list created by REST',
'Title': "Thorstens List"
};
$http(ShareCoffee.REST.build.create.for.angularJS({url: "web/lists/", payload: payload}))
.success(function (data) {
ShareCoffee.UI.showNotification('List has been created');
$scope.refreshLists();
$scope.customListId = data.d.Id;
})
.error(function (data,status) {
console.log(data);
console.log(status)
});description TODO
var payload = {
'__metadata': { 'type': 'SP.List' },
'Title': 'CHANGED BY REST - Thorstens list'
};
$http(ShareCoffee.REST.build.update.for.angularJS(
{url: "web/lists('" + $scope.customListId + "')", payload: payload}))
.success(function (data) {
ShareCoffee.UI.showNotification('List has been updated');
$scope.refreshLists();
});description: TODO
$http(ShareCoffee.REST.build.delete.for.angularJS({url: "web/lists('" + $scope.customListId + "')"}))
.success(function (data) {
ShareCoffee.UI.showNotification('List has been deleted');
$scope.refreshLists();
});