Skip to content

Commit 230fbe4

Browse files
waldekmastykarzVesaJuvonen
authored andcommitted
Updated guidance to the latest version of SPFx (SharePoint#920)
* Updated tutorial on building web parts using AngularJS * Updated tutorial on migrating AngularJS applications * Updated localization guidance
1 parent 1c5b33f commit 230fbe4

9 files changed

+155
-152
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
-77.2 KB
Binary file not shown.
Binary file not shown.
-146 KB
Binary file not shown.

docs/spfx/web-parts/guidance/build-client-side-web-parts-with-angular-1-x.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2-
title: Build SharePoint Framework client-side web parts with Angular v1.x
2+
title: Build SharePoint Framework client-side web parts with AngularJS
33
ms.date: 09/25/2017
44
ms.prod: sharepoint
55
---
66

77

8-
# Build SharePoint Framework client-side web parts with Angular v1.x
8+
# Build SharePoint Framework client-side web parts with AngularJS
99

10-
If you are familiar with Angular, you can also use this extremely popular framework to build client-side web parts. Thanks to its modularity, it can be used for anything ranging from complex multi-view Single Page Applications to smaller components such as web parts. Many organizations have been using Angular for building SharePoint solutions in the past. This article shows how to use Angular v1.x to build a SharePoint Framework client-side web part and have it styled using [Office UI Fabric](http://dev.office.com/fabric). During this tutorial you will build a simple web part that manages to do items.
10+
If you are familiar with AngularJS, you can also use this extremely popular framework to build client-side web parts. Thanks to its modularity, it can be used for anything ranging from complex multi-view Single Page Applications to smaller components such as web parts. Many organizations have been using AngularJS for building SharePoint solutions in the past. This article shows how to use AngularJS to build a SharePoint Framework client-side web part and have it styled using [Office UI Fabric](http://dev.office.com/fabric). During this tutorial you will build a simple web part that manages to do items.
1111

12-
![SharePoint Framework client-side web part built using Angular displayed in SharePoint workbench](../../../images/ng-intro-hide-finished-tasks.png)
12+
![SharePoint Framework client-side web part built using AngularJS displayed in SharePoint workbench](../../../images/ng-intro-hide-finished-tasks.png)
1313

1414
The source of the working web part is available on GitHub at [https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/angular-todo](https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/angular-todo).
1515

@@ -48,30 +48,30 @@ Once the scaffolding completes, open your project folder in your code editor. In
4848

4949
![SharePoint Framework project open in Visual Studio Code](../../../images/ng-intro-project-visual-studio-code.png)
5050

51-
## Add Angular
51+
## Add AngularJS
5252

53-
In this tutorial you will load Angular from CDN. To do that, in the code editor, open the **config/config.json** file and in the **externals** property add the following lines:
53+
In this tutorial you will load AngularJS from CDN. To do that, in the code editor, open the **config/config.json** file and in the **externals** property add the following lines:
5454

5555
```json
5656
"angular": {
57-
"path": "https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js",
57+
"path": "https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.6/angular.min.js",
5858
"globalName": "angular"
5959
}
6060
```
6161

62-
![Angular added to the config.json file](../../../images/ng-intro-angular-config.png)
62+
![AngularJS added to the config.json file](../../../images/ng-intro-angular-config.png)
6363

64-
## Add Angular typings for TypeScript
64+
## Add AngularJS typings for TypeScript
6565

66-
Because you will be referencing Angular in your web part's code, you also need Angular typings for TypeScript. To install them run in the command line:
66+
Because you will be referencing AngularJS in your web part's code, you also need AngularJS typings for TypeScript. To install them run in the command line:
6767

6868
```sh
6969
npm install @types/angular --save-dev
7070
```
7171

72-
## Implement Angular application
72+
## Implement AngularJS application
7373

74-
With all prerequisites in place you can start implementing the sample Angular application. Because it will consist of a few files, create a separate folder for it called **app**.
74+
With all prerequisites in place you can start implementing the sample AngularJS application. Because it will consist of a few files, create a separate folder for it called **app**.
7575

7676
![The app folder highlighted in Visual Studio Code](../../../images/ng-intro-app-folder.png)
7777

@@ -307,7 +307,7 @@ export default class HomeController {
307307

308308
![The HomeController.ts file opened in Visual Studio Code](../../../images/ng-intro-homecontroller.png)
309309

310-
You start by loading the previously implemented data service. The controller needs it in order to get the list of items and modify items as requested by the user. Using Angular's dependency injection the service is injected into the controller. The controller implements a number of functions that are exposed to the view model and will be called from the template. Using these functions users will be able to add new items, mark items as finished, to do, or delete items.
310+
You start by loading the previously implemented data service. The controller needs it in order to get the list of items and modify items as requested by the user. Using AngularJS's dependency injection the service is injected into the controller. The controller implements a number of functions that are exposed to the view model and will be called from the template. Using these functions users will be able to add new items, mark items as finished, to do, or delete items.
311311

312312
### Implement the main module
313313

@@ -327,13 +327,13 @@ todoapp
327327

328328
![The app-module.ts file opened in Visual Studio Code](../../../images/ng-intro-app-module.png)
329329

330-
You start by referencing Angular and by loading previously implemented controller and data service. Next, you define the module for your application. Finally, you register the controller and data service with your application.
330+
You start by referencing AngularJS and by loading previously implemented controller and data service. Next, you define the module for your application. Finally, you register the controller and data service with your application.
331331

332-
Now you've built an Angular application for your web part. In the following steps you will register the Angular application with the web part and make it configurable using web part properties.
332+
Now you've built an AngularJS application for your web part. In the following steps you will register the AngularJS application with the web part and make it configurable using web part properties.
333333

334-
## Register Angular application with web part
334+
## Register AngularJS application with web part
335335

336-
Next step is to add Angular application to the web part. In the code editor open the **ToDoWebPart.ts** file.
336+
Next step is to add AngularJS application to the web part. In the code editor open the **ToDoWebPart.ts** file.
337337

338338
Just before the class declaration, add the following lines:
339339

@@ -344,15 +344,15 @@ import './app/app-module';
344344

345345
![Import statements in the ToDoWebPart.ts file highlighted in Visual Studio Code](../../../images/ng-intro-web-part-import-angular.png)
346346

347-
This allows us to load a reference to Angular and your application, both of which you need to bootstrap your Angular application.
347+
This allows us to load a reference to AngularJS and your application, both of which you need to bootstrap your AngularJS application.
348348

349349
Change the web part's **render** function to:
350350

351351
```ts
352352
public render(): void {
353353
if (this.renderedOnce === false) {
354354
this.domElement.innerHTML = `
355-
<div class="${styles.toDoWebPart}">
355+
<div class="${styles.toDo}">
356356
<div data-ng-controller="HomeController as vm">
357357
<div class="${styles.loading}" ng-show="vm.isLoading">
358358
<div class="${styles.spinner}">
@@ -398,12 +398,12 @@ public render(): void {
398398

399399
![Web part's render function in Visual Studio Code](../../../images/ng-intro-web-part-render-angular.png)
400400

401-
The code first assigns the template of your application directly to the web part's DOM element. On the root element you specify the name of the controller that will handle events and data binding in the template. Then, you bootstrap your application using the **todoapp** name you used previously when declaring the main module. Using the **renderedOnce** web part property you ensure that your Angular application is bootstrapped only once. Without it, if you changed one of the web part's properties, the **render** function would be invoked again bootstrapping the Angular application again, which would lead to an error.
401+
The code first assigns the template of your application directly to the web part's DOM element. On the root element you specify the name of the controller that will handle events and data binding in the template. Then, you bootstrap your application using the **todoapp** name you used previously when declaring the main module. Using the **renderedOnce** web part property you ensure that your AngularJS application is bootstrapped only once. Without it, if you changed one of the web part's properties, the **render** function would be invoked again bootstrapping the AngularJS application again, which would lead to an error.
402402

403403
You also need to implement CSS styles that you are using the template. In the code editor open the **ToDo.module.scss** file and replace its contents with:
404404

405405
```css
406-
.toDoWebPart {
406+
.toDo {
407407
.loading {
408408
margin: 0 auto;
409409
width: 6em;
@@ -674,7 +674,7 @@ Start by adding configuration property in the web part manifest. In the code edi
674674

675675
Next, update the signature of the web part properties interface.
676676

677-
In the code editor open the **IToDoWebPartProps.ts** file and replace its contents with the following:
677+
In the code editor open the **ToDoWebPart.ts** file and update the `IToDoWebPartProps` interface to the following:
678678

679679
```ts
680680
export interface IToDoWebPartProps {
@@ -729,14 +729,14 @@ protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
729729
To fix the missing string references you first need to change the signature of your strings. In the code editor open the **loc/mystrings.d.ts** file and change its contents to:
730730

731731
```ts
732-
declare interface IToDoStrings {
732+
declare interface IToDoWebPartStrings {
733733
PropertyPaneDescription: string;
734-
ViewGroupName: string;
734+
BasicGroupName: string;
735735
HideFinishedTasksFieldLabel: string;
736736
}
737737

738-
declare module 'toDoStrings' {
739-
const strings: IToDoStrings;
738+
declare module 'ToDoWebPartStrings' {
739+
const strings: IToDoWebPartStrings;
740740
export = strings;
741741
}
742742
```
@@ -767,13 +767,13 @@ In the web part property pane you should see a toggle button for your newly defi
767767

768768
![Toggle button displayed on the web part property pane](../../../images/ng-intro-property-pane-toggle-browser.png)
769769

770-
At this point clicking the toggle button doesn't have any effect on your web part as it hasn't been connected to Angular. You will do that in the next step.
770+
At this point clicking the toggle button doesn't have any effect on your web part as it hasn't been connected to AngularJS. You will do that in the next step.
771771

772-
### Make the Angular application configurable using web part properties
772+
### Make the AngularJS application configurable using web part properties
773773

774-
In the previous step you defined a web part property that allows users to choose whether to show completed tasks or not. Next you will pass the value selected by the user into the Angular application so that it can load items accordingly.
774+
In the previous step you defined a web part property that allows users to choose whether to show completed tasks or not. Next you will pass the value selected by the user into the AngularJS application so that it can load items accordingly.
775775

776-
#### Broadcast Angular event on web part property change
776+
#### Broadcast AngularJS event on web part property change
777777

778778
In the code editor open the **ToDoWebPart.ts** file. Right before web part's constructor add the following line:
779779

@@ -789,7 +789,7 @@ Next, change the web part's **render** function to the following:
789789
public render(): void {
790790
if (this.renderedOnce === false) {
791791
this.domElement.innerHTML = `
792-
<div class="${styles.toDoWebPart}">
792+
<div class="${styles.toDo}">
793793
<div data-ng-controller="HomeController as vm">
794794
<div class="${styles.loading}" ng-show="vm.isLoading">
795795
<div class="${styles.spinner}">
@@ -837,9 +837,9 @@ public render(): void {
837837
}
838838
```
839839

840-
In the above code sample, every time the web part property is changed, it will broadcast an Angular event to which the Angular application will subscribe it. When event is received by the Angular application, it will then handle that accordingly.
840+
In the above code sample, every time the web part property is changed, it will broadcast an AngularJS event to which the AngularJS application will subscribe it. When event is received by the AngularJS application, it will then handle that accordingly.
841841

842-
#### Subscribe to web part property change event in Angular
842+
#### Subscribe to web part property change event in AngularJS
843843

844844
In the code editor open the **app/HomeController.ts** file. Extend the constructor as follows:
845845

@@ -856,7 +856,7 @@ constructor(private dataService: IDataService, private $window: angular.IWindowS
856856

857857
![Constructor definition in the HomeController.ts file highlighted in Visual Studio Code](../../../images/ng-intro-homecontroller-event.png)
858858

859-
To verify that the Angular application is working as expected and correctly responds to property changed, in the command line run:
859+
To verify that the AngularJS application is working as expected and correctly responds to property changed, in the command line run:
860860

861861
```sh
862862
gulp serve

0 commit comments

Comments
 (0)