I need to update my application view based on events from a service.
One of my services is injecting the ChangeDetectorRef. Compilation is successful, but I am encountering an error in the browser during App bootstrap:
No provider for ChangeDetectorRef!
.
I initially thought I should include it in my AppModule, but I couldn't find any documentation suggesting that it is importable there. Adding the class itself to the import array resulted in an error. Likewise, adding it to the providers array in the module caused an error as well. Below is a simplified version of my service:
import {Injectable, ChangeDetectorRef } from '@angular/core';
@Injectable()
export class MyService {
private count: number = 0;
constructor(private ref: ChangeDetectorRef){}
increment() {
this.count++;
this.ref.detectChanges();
}
And here is the app module:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { MyService } from './my.service';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
providers: [ MyService ],
booststrap: [ AppComponent ]
})
export AppModule {}
UPDATE
I attempted to remove my use of ChangeDetectorRef, but the issue persists. It seems like there may be an issue with how I updated my System JS config.
The initial app was created using angular-cli, and I decided to manually update Angular since they hadn't done so yet. However, with the release of Angular 2.0.0, angular-cli has been updated to support the latest version of Angular. I will follow their upgrade procedures and hopefully resolve the problem.
Update 2
The webpack/angular-cli update went smoothly. The app now successfully builds with Angular 2.0.0 and angular-cli 1.0.0-beta14. However, the browser still shows the same error. Removing ChangeDetectorRef from the service didn't truly fix the issue as I realized it was being used in two services. By removing it from both files, the app loads successfully except for areas where ChangeDetectorRef was needed. Reintroducing it into one file triggers an error about the provider not being found.
I tried importing it into my module, but since it's not a module itself, the transpiler raises an error. Listing it as a provider in the module also failed since it lacks a 'provide' property. Similar issues arise if I attempt to include it in the declarations array.