SharePoint Framework and Angular 4/5 with multiple webparts

Brass Contributor

Hi,
I am trying to create SPFx multiple web parts with Angular 4. I have created 'App' folder under webparts folder and trying to run the project. I am able to run first web part but when adding second webpart , It is throwing errors.

I am attaching my code here.
Can you please suggest, How can I use angular 4 with only one app folder in SPFx with multiple webparts?

Thanks,
Gaurav


2 Replies

i also face exact issue in spfx web part. i am searching the solution ofr this. if you got the solution for this issue please share answer with me. following are packages : 

 "@angular/animations": "~4.0.0",
    "@angular/common": "~4.0.0",
    "@angular/compiler": "~4.0.0",
    "@angular/core": "~4.0.0",
    "@angular/forms": "~4.0.0",
    "@angular/http": "~4.0.0",
    "@angular/platform-browser": "~4.0.0",
    "@angular/platform-browser-dynamic": "~4.0.0",
    "@angular/router": "~4.0.0",
    "@microsoft/sp-core-library": "1.9.1",
    "@microsoft/sp-lodash-subset": "1.9.1",
    "@microsoft/sp-office-ui-fabric-core": "1.9.1",
    "@microsoft/sp-webpart-base": "1.9.1",
    "@types/es6-promise": "0.0.33",
    "@types/webpack-env": "1.13.1",
    "classlist.js": "^1.1.20150312",
    "lodash": "^4.17.4",
    "reflect-metadata": "0.1.10",
    "rxjs": "~5.0.1",
    "systemjs": "0.19.40",
    "typescript-string-operations": "~1.1.0",
    "typings": "^2.1.1",
    "zone.js": "~0.8.4"

@Gaurav Goyal This is an issue with how Angular bootstraps it's solutions. In the Angular 2+ world, only 1 "app" can live on a page at a time. Because of this, it doesn't really work when you want to use it in SharePoint.

In order to make it work, you'd need to use Angular Elements. Which has many cons. For more information, check out Andrew Connell's blog on this matter.
https://www.andrewconnell.com/blog/using-angular-elements-in-sharepoint-framework-projects