{"id":77,"date":"2018-05-20T21:51:00","date_gmt":"2018-05-20T21:51:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2018\/05\/20\/how-to-display-logged-in-user-details-using-angularjs\/"},"modified":"2019-02-16T22:27:56","modified_gmt":"2019-02-16T21:27:56","slug":"how-to-display-logged-in-user-details-using-angularjs","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/how-to-display-logged-in-user-details-using-angularjs\/","title":{"rendered":"How to Display Logged-In User Details Using AngularJS"},"content":{"rendered":"<p>Hey! Good to see you!<\/p>\n<p>Let&#8217;s keep it simple this time. I would just give you:<\/p>\n<ul>\n<li>the HTML code<\/li>\n<li>the AngularJS Script<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>We would like to display the users <em>Firstname<\/em>, <em>Lastname<\/em>, <em>email<\/em> and <em>Department<\/em><\/p>\n<p>Then I would tell you the files you need to\u00a0 include in your header.<\/p>\n<p>&nbsp;<\/p>\n<p><b>File to Include in your Header<\/b><br \/>\nYou need to include Bootstrap, JQuery and AngularJS in the header section of your html page<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type=<\/span><span style=\"background-color: #fff0f0;\">\"application\/javascript\"<\/span> <span style=\"color: #0000cc;\">src=<\/span><span style=\"background-color: #fff0f0;\">\"jquery.min.js\"<\/span><span style=\"color: #007700;\">&gt;&lt;\/script&gt;<\/span>  \r\n<span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type=<\/span><span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span> <span style=\"color: #0000cc;\">src=<\/span><span style=\"background-color: #fff0f0;\">\"bootstrap.js\"<\/span><span style=\"color: #007700;\">&gt;<\/span> <span style=\"color: #007700;\">&lt;\/script&gt;<\/span> \r\n<span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type=<\/span><span style=\"background-color: #fff0f0;\">\"application\/javascript\"<\/span> <span style=\"color: #0000cc;\">src=<\/span><span style=\"background-color: #fff0f0;\">\"angular.js\"<\/span><span style=\"color: #007700;\">&gt;&lt;\/script&gt;<\/span><\/pre>\n<p>Listing 1: Header Files<\/p>\n<p>&nbsp;<\/p>\n<p><b>AngularJS Script<\/b><br \/>\nThe AngularJS script is given below. You need to enclose it in a &lt;script&gt;&lt;\/script&gt;<br \/>\ntag.<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #008800; font-weight: bold;\">var<\/span> ShowUser <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">function<\/span>(){\r\n  $http({\r\n  url<span style=\"color: #333333;\">:<\/span> baseUrl <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\"api\/user\"<\/span>,  <span style=\"color: #888888;\">\/\/The Base URL depends on your sharepoint server<\/span>\r\n  method<span style=\"color: #333333;\">:<\/span> <span style=\"background-color: #fff0f0;\">\"GET\"<\/span>,\r\n  headers<span style=\"color: #333333;\">:<\/span> { <span style=\"background-color: #fff0f0;\">\"Accept\"<\/span><span style=\"color: #333333;\">:<\/span> <span style=\"background-color: #fff0f0;\">\"application\/json; odata=verbose\"<\/span> }\r\n  }).then(<span style=\"color: #008800; font-weight: bold;\">function<\/span> mySucces(response) {\r\n   $scope.DisplayName <span style=\"color: #333333;\">=<\/span> response.data.First_Name <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">', '<\/span> <span style=\"color: #333333;\">+<\/span> response.data.Last_Name;\r\n   $scope.Location <span style=\"color: #333333;\">=<\/span> response.data.City;\r\n   $scope.Department <span style=\"color: #333333;\">=<\/span> response.data.Department;\r\n   $scope.TotalPoints <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">280<\/span>;\r\n}, <span style=\"color: #008800; font-weight: bold;\">function<\/span> error(response) {\r\nconsole.log(response);\r\n});\r\n};\r\n<\/pre>\n<p><b>Listing 2<\/b>: AngularJS Script<\/p>\n<p>&nbsp;<\/p>\n<p>The script retrieves the user&#8217;s details from a the Request URL. Then it places the retrieved data in the $Scope variable. Data placed in the $Scope is accessible from the html page by using the {{}}\u00a0 to enclose the variable name. That&#8217;s all you need<\/p>\n<p>&nbsp;<\/p>\n<p><b>The HTML Code<\/b><br \/>\nThe HTML section that displays the\u00a0 user details is given below. You can modify it to fit your page design.<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #007700;\">&lt;ul&gt;<\/span>\r\n <span style=\"color: #007700;\">&lt;li&gt;<\/span>{{DisplayName}}<span style=\"color: #007700;\">&lt;\/li&gt;<\/span>\r\n <span style=\"color: #007700;\">&lt;li&gt;<\/span>{{Department}} <span style=\"color: #007700;\">&lt;\/li&gt;<\/span>\r\n <span style=\"color: #007700;\">&lt;li&gt;<\/span>{{Location}}<span style=\"color: #007700;\">&lt;\/li&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/ul&gt;<\/span><\/pre>\n<p>Listing 3: HTML Code<\/p>\n<p>&nbsp;<\/p>\n<p>Make sure you try it and let me know if you have any challenges.<br \/>\nThanks .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey! Good to see you! Let&#8217;s keep it simple this time. I would just give you: the HTML code the AngularJS Script &nbsp; We would &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[113],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/77"}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":2,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":620,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/77\/revisions\/620"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}