How to manage Angular2 “expression has changed after it was checked” exception when a component property depends on current datetime

Run change detection explicitly after the change: import { ChangeDetectorRef } from ‘@angular/core’; constructor(private cdRef:ChangeDetectorRef) {} ngAfterViewChecked() { console.log( “! changement de la date du composant !” ); this.dateNow = new Date(); this.cdRef.detectChanges(); }

How to force a component’s re-rendering in Angular 2?

Rendering happens after change detection. To force change detection, so that component property values that have changed get propagated to the DOM (and then the browser will render those changes in the view), here are some options: ApplicationRef.tick() – similar to Angular 1’s $rootScope.$digest() — i.e., check the full component tree NgZone.run(callback) – similar to … Read more

If ” is an Angular component, then verify that it is part of this module

Your MyComponentComponent should be in MyComponentModule. And in MyComponentModule, you should place the MyComponentComponent inside the “exports”. Something like this, see code below. @NgModule({ imports: [], exports: [MyComponentComponent], declarations: [MyComponentComponent], providers: [], }) export class MyComponentModule { } and place the MyComponentModule in the imports in app.module.ts like this (see code below). import { MyComponentModule … Read more

How can I use/create dynamic template to compile dynamic Component with Angular 2.0?

EDIT – related to 2.3.0 (2016-12-07) NOTE: to get solution for previous version, check the history of this post Similar topic is discussed here Equivalent of $compile in Angular 2. We need to use JitCompiler and NgModule. Read more about NgModule in Angular2 here: Angular 2 RC5 – NgModules, Lazy Loading and AoT compilation In … Read more

Angular 2 – How do I navigate to another route using this.router.parent.navigate(‘/about’)?

Absolute path routing There are 2 methods for navigation, .navigate() and .navigateByUrl() You can use the method .navigateByUrl() for absolute path routing: import {Router} from ‘@angular/router’; constructor(private router: Router) {} navigateToLogin() { this.router.navigateByUrl(‘/login’); } You put the absolute path to the URL of the component you want to navigate to. Note: Always specify the complete … Read more

How to enable production mode?

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.

Angular – What is the meanings of module.id in component?

The beta release of Angular (since vesion 2-alpha.51) supports relative assets for components, like templateUrl and styleUrls in the @Component decorator. module.id works when using CommonJS. You don’t need to worry about how it works. Remember: setting moduleId: module.id in the @Component decorator is the key here. If you don’t have that then Angular 2 … Read more

Angular 2 router no base href set

https://angular.io/docs/ts/latest/guide/router.html Add the base element just after the <head> tag. If the app folder is the application root, as it is for our application, set the href value exactly as shown here. The <base href=”https://stackoverflow.com/”> tells the Angular router what is the static part of the URL. The router then only modifies the remaining part … Read more

Angular 2: 404 error occur when I refresh through the browser [duplicate]

Update for Angular 2 final version In app.module.ts: Add imports: import { HashLocationStrategy, LocationStrategy } from ‘@angular/common’; And in NgModule provider, add: {provide: LocationStrategy, useClass: HashLocationStrategy} Example (app.module.ts): import { NgModule } from ‘@angular/core’; import { BrowserModule } from ‘@angular/platform-browser’; import { AppComponent } from ‘./app.component’; import { HashLocationStrategy, LocationStrategy } from ‘@angular/common’; @NgModule({ declarations: … Read more