2

I'm facing this error while doing tsc. However, my app seems working. error TS1184: Modifiers cannot appear here.

I'm calling Run App from Index.html

export function RunApplication(url:string)
{
    platformBrowserDynamic().bootstrapModule(createAppModule(url));

}

export function createAppModule(url:string) 
{
    @NgModule({ 
      ..... standard RC5 code here per docs
    })
 export class AppModule {}
    return AppModule;
}
Robin Kedia
  • 283
  • 3
  • 16

4 Answers4

2

The problem is that you are exporting the function already, so export inside the function is not necessary, removing it should fix the problem.

export function createAppModule(url:string) 
{
    @NgModule({ 
      ..... standard RC5 code here per docs
    })
  class AppModule {}
    return AppModule;
}
Ignatius Andrew
  • 8,012
  • 3
  • 54
  • 54
0

I don't think you want to put the module in a function. Try something like this instead

@NgModule({ 
    // ..... standard RC5 code here per docs
})
export class AppModule {}


platformBrowserDynamic().bootstrapModule(AppModule);
qfwfq
  • 2,416
  • 1
  • 17
  • 30
  • How would I pass value to my app module coming from server than? – Robin Kedia Aug 20 '16 at 01:12
  • Are you talking about routing? If so, look at https://angular.io/docs/ts/latest/guide/router.html. If not, I am not sure what you mean. – qfwfq Aug 20 '16 at 01:16
  • Robin is talking about injecting an external parameter(s) during bootstrap on the client side, with startup values being passed in from the page/server. The previously documented technique with passing providers into bootstrapModule() does not work in RC5, and wrapping root module into a function seems like a good workaround: http://stackoverflow.com/questions/38948463/passing-server-parameters-to-ngmodule-after-rc5-upgrade But when I try that, I get the same error as the OP. For me though, TSC (v2.0.0) refuses to transpile the source files. I wonder if this was a non-issue with TSC v1.8 – Alex Lobakov Sep 01 '16 at 16:34
0

Found the cause of this: Just remove the "export" modifier before "class AppModule" declaration, and everything compiles! It's very easy to leave it behind after wrapping a static module declaration into a function.

Alex Lobakov
  • 704
  • 1
  • 6
  • 8
0

Presumably you want to provide some dynamic data to your application pre-bootstrap?

As already stated, the issue is caused by the export on the class. Remove it and the error will go away.

See here for a reasonable example.

Community
  • 1
  • 1
MJP
  • 75
  • 1
  • 7