[英]getting currently logged in user from sharepoint hosted angular app
I'm trying to figure out how to get at least the currently logged in sharepoint user's id from within a sharepoint-hosted angular sharepoint app. 我试图弄清楚如何从共享点托管的角度共享点应用程序中至少获取当前登录的共享点用户的ID。 I'm unable to call libraries outside of angular and get the value back and apply it to my angular model.
我无法调用angular以外的库并将其取回并将其应用于我的angular模型。 does anyone know how to do this?
有谁知道如何做到这一点?
The _spcontextinfo is null even when i get it using the $windows service or when i try using this code 即使使用$ windows服务获取_spcontextinfo还是尝试使用此代码 ,_spcontextinfo也为null
and I cannot figure out how to call spservices with something like 而且我不知道如何用类似的东西来调用spservices
var thisUsersValues = $().SPServices.SPGetCurrentUser({ fieldNames: ["ID", "Name", "SIP Address"], debug: false });
https://spservices.codeplex.com/wikipage?title=$().SPServices.SPGetCurrentUser&referringTitle=Documentation
what do I need to do in angular to call this code that normally would work in regular javascript? 我需要做些什么才能调用通常在常规javascript中工作的代码?
Getting the SharePoint logged in user without any libraries will be a little tough. 在没有任何库的情况下让SharePoint登录用户会有些困难。 Ideally, you would want to use jQuery and SPServices.JS and it would be relatively straight forward.
理想情况下,您将要使用jQuery和SPServices.JS,并且相对来说比较简单。 However, since you don't want to use a 3rd party library, I would suggest calling one of SharePoints built in web services via your JavaScript.
但是,由于您不想使用第三方库,因此建议您通过JavaScript调用内置于Web服务中的SharePoint之一。
You can use SharePoint Client Object Model. 您可以使用SharePoint客户端对象模型。 This is a possible solution for you
这是您可能的解决方案
http://www.instantquick.com/index.php/using-the-sharepoint-client-object-model-in-angularjs-apps?c=elumenotion-blog-archive/random-whatnot http://www.instantquick.com/index.php/using-the-sharepoint-client-object-model-in-angularjs-apps?c=elumenotion-blog-archive/random-whatnot
Built a Angular Factory 建一个角工厂
//Angular service Wrapper for ClientContext executeQuery.
//The $q service makes it easy to wrap SharePoint's context.executeQueryAsync for use with Angular
var module = angular.module('iqPart', [])
.factory('SharePointService', ['$q', function ($q) {
var SharePointService = {};
SharePointService.executeQuery = function (context) {
var deferred = $q.defer();
context.executeQueryAsync(deferred.resolve, function (o, args) {
deferred.reject(args);
});
return deferred.promise;
};
return SharePointService;
}]);
Usage within Angular Controller Angular Controller中的用法
var iqAppPartModule = angular.module('iqAppPartModule', []);
var iqAppPartController = iqAppPartController || {};
iqAppPartController.IQAppPart = function ($scope, sharePointService) {
//Make a request for the user
var ctx = SP.ClientContext.get_current();
var user = ctx.get_web().get_currentUser();
ctx.load(user);
sharePointService.executeQuery(ctx)
.then(function () {
$scope.UserName = user.get_title();
},
function (error) {
alert(error.get_message());
});
};
iqAppPartModule.controller('IQAppPart', ['$scope', 'SharePointService', iqAppPartController.IQAppPart]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.