0

I have sharepoint add-in project, I have inculuded necessary angular2 packages and ts files as you see ss of solution explorer in below:

enter image description here

and here is my ts file contents; boot.ts

import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent)

app.component.ts

import {Welcome} from './app.module';
import {Component} from 'angular2/core';
@Component({
    selector: 'app-main',
    template:'<h1>${Welcome.getMessage()}</h1>'
})
export class AppComponent {}

app.module.ts

export class Welcome {
    static getMessage() {
        return "Hello World!";
    }
}

when I run this application I always get this error message in output window:

> @"Error 1
>         CorrelationId: ae2bcaba-cdac-4178-bd39-2aca278a2e31
>         ErrorDetail: There was a problem with activating the app web definition.
>         ErrorType: App
>         ErrorTypeName: App Related
>         ExceptionMessage: Failed to instantiate file "app.module.ts" from module "RootModule": Source path
> "Features\SharePointAddIn4_Feature1\app.module.ts" not found.
>         Source: AppWeb
>         SourceName: App Web Deployment

I have search but cant find any solution helped me.. any idea how to fix this?

TyForHelpDude
  • 4,828
  • 10
  • 48
  • 96

2 Answers2

1

To resolve this, I had to set the tsconfig.json file (and others) to not deploy, and remove it from Elements.xml in the root of the project.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="RootModule">
  </Module>
</Elements>
moonpatrol
  • 1,202
  • 11
  • 15
0

Hey Buddy there are few points to be clear here before answer

  • you are using too old version of angular2 may be you are in angular2 beta (as you are using 'angular2/core' now it is '@angular/*')

  • you are using wrong syntax according to me

    {Welcome.getMessage()}

there are syntax like this

{{Welcome.getMessage()}}
  • also you are trying to access class Welcome without even initializing in the constructor of app.component.ts file, which is wrong .
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
  • but my tsc -v output is 2.0.10 ? if I change 'angular2/platform/browser' to '@angular/platform/browser' it shows an error "can not find module.." – TyForHelpDude Dec 04 '16 at 22:00
  • Yes, as I already said you have to upgrade your angular version to final in your package.json file, than run the command npm install – Pardeep Jain Dec 05 '16 at 03:42