I was reading related questions and I found this one, but my question is how can I switch from development to production mode. There are some differences between the modes w
ng build --prod
replaces environment.ts with environment.prod.ts
ng build --prod
My Angular 2 project doesn't have the "main.ts" file mentioned other answers, but it does have a "boot.ts" file, which seems to be about the same thing. (The difference is probably due to different versions of Angular.)
Adding these two lines after the last import
directive in "boot.ts" worked for me:
import { enableProdMode } from "@angular/core";
enableProdMode();
When ng build command is used it overwrite environment.ts file
By default when ng build command is used it set dev environment
In order to use production environment, use following command ng build --env=prod
This will enable production mode and automatically update environment.ts file
you can use in your app.ts || main.ts file
import {enableProdMode} from '@angular/core';
enableProdMode();
bootstrap(....);
You enable it by importing and executing the function (before calling bootstrap):
import {enableProdMode} from '@angular/core';
enableProdMode();
bootstrap(....);
But this error is indicator that something is wrong with your bindings, so you shouldn't just dismiss it, but try to figure out why it's happening.
The best way to enable the production mode for an Angular 2 application, is to use angular-cli and build the application with ng build --prod
. This will build the application with production profile. Using angular-cli has the benefit of being able to use development mode using ng serve
or ng build
while developing without altering the code all the time.