Angular 2/4 (BETA)
Angular view for Cerebral.
Install
npm install @cerebral/angular @angular/core @angular/platform-browser babel-plugin-transform-decorators-legacy
CerebralService
The Cerebral service exposes the Cerebral controller to your application.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { provide } from 'cerebral'
import { ControllerService } from '@cerebral/angular'
import { AppComponent } from './app.component.ts'
import { SomeAngularService } from './SomeAngularService'
export function configureController(someAngularService : SomeAngularService) {
return new ControllerService({
providers: [
provide('someAngularService', someAngularService)
]
})
})
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ],
providers: [
{
provide: ControllerService,
useFactory: configureController,
deps: [SomeAngularService]
},
]
})
export class AppModule {}
connect decorator
The connect decorator connects state and signals to your components.
import { Component, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'
import { signal, state } from 'cerebral/tags'
import { connect, ControllerService, CerebralComponent } from '@cerebral/angular'
@Component({
selector: 'app-component',
template: `
<div (click)="onClick()">{{foo}}</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
@connect({
myName: state(['foo']),
onClick: signal(['clicked'])
})
export class AppComponent extends CerebralComponent {
constructor(cdr: ChangeDetectorRef, controller: ControllerService) {
super(cdr, controller)
controller.getSignal('onClick')()
}
}