-1

I am a beginner for angular 4. I am trying to make a simple example but whenever I am going to enable production mode enableProdMode();. this function gives me an error. tell me where I should write this. Tell me where should I write this function and why?

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {enableProdMode} from '@angular/core';


import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,FormsModule
  ],
  providers: [],
  enableProdMode();
  bootstrap: [AppComponent]
})
export class AppModule { }

It gives me

C:/Users/Home/Desktop/angdemo/second/src/app/app.module.ts (18,3): ',' expected.

Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
Sonu
  • 1
  • 2
  • enableProdMode(); <-- ";" must be a comma – Eliseo Oct 05 '17 at 07:54
  • Hey Eliseo after giving comma(,) like this enableProdMode(), it gives me another error : ERROR in C:/Users/Home/Desktop/angdemo/second/src/app/app.module.ts (17,19): '{' expected. – Sonu Oct 05 '17 at 08:03
  • Please put more care into what you write, you have a mistake in the title (!) which means you never even read it once. – Maciej Jureczko Oct 05 '17 at 08:31

2 Answers2

0

Generally it is not necessary to import

 import { enableProdMode } from '@angular/core';

inside app.module.ts, you can have an environment.ts or main.ts to defined the mode and import it. Remove it from app.module.ts, it should be fine.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Sajeetharan I already have all this things in main.ts my main.ts: import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';import { AppModule } from './app/app.module'; import { environment } from './environments/environment'; if (environment.production) { enableProdMode();}platformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.log(err)); – Sonu Oct 05 '17 at 08:19
  • but after compiling successfully I got this one as Angular is running in the development mode. Call enableProdMode() to enable the production mode.thats why I am trying to eanable production mode in app.module.ts as mentioned in "https://stackoverflow.com/questions/35721206/how-to-enable-production-mode-in-angular-2 " – Sonu Oct 05 '17 at 08:19
  • @Sonu yeah but not in app.module.ts its in main.ts – Sajeetharan Oct 05 '17 at 08:31
  • Thanks Sajeetharan, export const environment = { production: true }; in envirnment.ts worked for me.. – Sonu Oct 05 '17 at 08:52
0

Use the code like this : you should not call enableProdMode() inside @NgModule.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { enableProdMode } from '@angular/core';


import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,FormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})


  enableProdMode();

export class AppModule { }
Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66