This article will walk you through another way to create a SharePoint project with the latest version of Angular framework without using SharePoint framework.
Below are the following reasons for not targeting the SharePoint framework.
Create one document library under SiteAssets and name it AngularDocs.
Step 2
Create four folders inside the library for the following reasons.
employee - To keep all Angular build files.
html - To keep html file which is referred in content editor.
css - To store the css of static html file.
images - To store all the images used in project.
Create a proxy for SharePoint Online environment
Why proxy environment
To use the SharePoint functionality locally or on localhost.
Note
It is not necessary to create the proxy for SharePoint online environment but if we do not create it, then a single change in code requires us to build the project and upload it on Sharepoint in order to see the changes.
Step 1
To create an Angular project with Angular CLI, open the Command Prompt and type this command where proxy-server is an Angular project name.
ng new proxy-server
Step 2
Select the following options.
Would you like to add Angular routing? - n (Type n, as we do not require routing for proxy server).
Which stylesheet format would you like to use? CSS (You can choose any option, as we are not writing any css for proxy server).
Now it will install the necessary packages and files, once done open the proxy-server project in Visual Studio code.
Step 3
Install the required proxy library for our project (proxy-server) using this command. To learn more about this library follow this
link
npm install sp-rest-proxy --save-dev
Step 4
Create one js file at root location and name it server.js file, paste the below code in it.
-
-
- const RestProxy = require('sp-rest-proxy');
- const settings = {
- port: 8080,
- };
- const restProxy = new RestProxy(settings);
- restProxy.serve();
Step 5
Add the below line in package.json file under scripts tag.
"serve": "node ./server.js"
Step 6
Now type the following command to start the proxy server so that it can serve the request locally or on localhost.
npm run serve
Note
When you are running the above command the first time it will ask a few questions depending upon our Sharepoint environment.
Once the above step is completed, it will create a private.json file under config folder and start serving the sharepoint request on http://localhost:8080.
Remember one thing, whenever your password changes for your SharePoint account then delete the private.json file and run the above command again.
Conclusion
In this article we have achieved our first two activities of the SharePoint project using Angular.
Simply run npm install command in the command prompt after downloding the (proxyserver.zip) project from the attachment.
Check the next part of article.