SharePoint Framework and Angular 4/5 with multiple webparts

%3CLINGO-SUB%20id%3D%22lingo-sub-154839%22%20slang%3D%22en-US%22%3ESharePoint%20Framework%20and%20Angular%204%2F5%20with%20multiple%20webparts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-154839%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3CBR%20%2F%3EI%20am%20trying%20to%20create%20SPFx%20multiple%20web%20parts%20with%20Angular%204.%20I%20have%20created%20'App'%20folder%20under%20webparts%20folder%20and%20trying%20to%20run%20the%20project.%20I%20am%20able%20to%20run%20first%20web%20part%20but%20when%20adding%20second%20webpart%20%2C%20It%20is%20throwing%20errors.%3C%2FP%3E%0A%3CP%3EI%20am%20attaching%20my%20code%20here.%3CBR%20%2F%3ECan%20you%20please%20suggest%2C%20How%20can%20I%20use%20angular%204%20with%20only%20one%20app%20folder%20in%20SPFx%20with%20multiple%20webparts%3F%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%2C%3CBR%20%2F%3EGaurav%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-154839%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eangular%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESPFx%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1035757%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Framework%20and%20Angular%204%2F5%20with%20multiple%20webparts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1035757%22%20slang%3D%22en-US%22%3E%3CP%3Ei%20also%20face%20exact%20issue%20in%20spfx%20web%20part.%20i%20am%20searching%20the%20solution%20ofr%20this.%20if%20you%20got%20the%20solution%20for%20this%20issue%20please%20share%20answer%20with%20me.%20following%20are%20packages%20%3A%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%22%40angular%2Fanimations%22%3A%26nbsp%3B%22~4.0.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40angular%2Fcommon%22%3A%26nbsp%3B%22~4.0.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40angular%2Fcompiler%22%3A%26nbsp%3B%22~4.0.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40angular%2Fcore%22%3A%26nbsp%3B%22~4.0.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40angular%2Fforms%22%3A%26nbsp%3B%22~4.0.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40angular%2Fhttp%22%3A%26nbsp%3B%22~4.0.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40angular%2Fplatform-browser%22%3A%26nbsp%3B%22~4.0.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40angular%2Fplatform-browser-dynamic%22%3A%26nbsp%3B%22~4.0.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40angular%2Frouter%22%3A%26nbsp%3B%22~4.0.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40microsoft%2Fsp-core-library%22%3A%26nbsp%3B%221.9.1%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40microsoft%2Fsp-lodash-subset%22%3A%26nbsp%3B%221.9.1%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40microsoft%2Fsp-office-ui-fabric-core%22%3A%26nbsp%3B%221.9.1%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40microsoft%2Fsp-webpart-base%22%3A%26nbsp%3B%221.9.1%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40types%2Fes6-promise%22%3A%26nbsp%3B%220.0.33%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22%40types%2Fwebpack-env%22%3A%26nbsp%3B%221.13.1%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22classlist.js%22%3A%26nbsp%3B%22%5E1.1.20150312%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22lodash%22%3A%26nbsp%3B%22%5E4.17.4%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22reflect-metadata%22%3A%26nbsp%3B%220.1.10%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22rxjs%22%3A%26nbsp%3B%22~5.0.1%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22systemjs%22%3A%26nbsp%3B%220.19.40%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22typescript-string-operations%22%3A%26nbsp%3B%22~1.1.0%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22typings%22%3A%26nbsp%3B%22%5E2.1.1%22%2C%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22zone.js%22%3A%26nbsp%3B%22~0.8.4%22%3C%2FSTRONG%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1037166%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Framework%20and%20Angular%204%2F5%20with%20multiple%20webparts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1037166%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F51972%22%20target%3D%22_blank%22%3E%40Gaurav%20Goyal%3C%2FA%3E%26nbsp%3BThis%20is%20an%20issue%20with%20how%20Angular%20bootstraps%20it's%20solutions.%20In%20the%20Angular%202%2B%20world%2C%20only%201%20%22app%22%20can%20live%20on%20a%20page%20at%20a%20time.%20Because%20of%20this%2C%20it%20doesn't%20really%20work%20when%20you%20want%20to%20use%20it%20in%20SharePoint.%3CBR%20%2F%3E%3CBR%20%2F%3EIn%20order%20to%20make%20it%20work%2C%20you'd%20need%20to%20use%20Angular%20Elements.%20Which%20has%20many%20cons.%20For%20more%20information%2C%20check%20out%20Andrew%20Connell's%20blog%20on%20this%20matter.%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fwww.andrewconnell.com%2Fblog%2Fusing-angular-elements-in-sharepoint-framework-projects%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.andrewconnell.com%2Fblog%2Fusing-angular-elements-in-sharepoint-framework-projects%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional 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