ngx-model | Simple state management | Reactive Programming library
kandi X-RAY | ngx-model Summary
kandi X-RAY | ngx-model Summary
Angular Model. Simple state management with minimalistic API, one way data flow, multiple model support and immutable data exposed as RxJS Observable.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ngx-model
ngx-model Key Features
ngx-model Examples and Code Snippets
Community Discussions
Trending Discussions on ngx-model
QUESTION
See my code in stackblitz
Btn them is not applying though I have added ngx-bootstrap as dependency in stackblitz code. See my code here. https://stackblitz.com/edit/angular-ngx-model-example
Actually, I want to learn ngx-bootstrap model and other fundamental so to quickly check I am directly building code online in stackblitz.
...ANSWER
Answered 2019-Apr-21 at 19:53Looks like you forgot to include bootstrap styles as ngx-bootstrap documentation states:
You will need bootstrap styles (Bootstrap 3)
QUESTION
I am getting following error while i execute
ng build --prod
But
ng build
is working fine.
I have found many solutions for the same in the stack overflow but none of them worked
See error below: ...ANSWER
Answered 2018-Dec-20 at 09:09Can you verify that ModelComponet is a) in a module and b) that the module ends up imported in your AppModule?
Next step is, break it down to a simpler example and provide more code (including HTML where the component gets loaded, appmodule, featuremodule, component.ts).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ngx-model
Install ngx-model npm install --save ngx-model or yarn add ngx-model
Import and use NgxModelModule in you AppModule (or CoreModule) import { NgxModelModule } from 'ngx-model'; @NgModule({ imports: [ NgxModelModule ] }) export class CoreModule {}
Import and use Model and ModelFactory in your own services. import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { ModelFactory, Model } from 'ngx-model'; @Injectable() export class TodosService { private model: Model<Todo[]>; todos$: Observable<Todo[]>; constructor(private modelFactory: ModelFactory<Todo[]>) { this.model = this.modelFactory.create([]); // create model and pass initial data this.todos$ = this.model.data$; // expose model data as named public property } toggleTodo(id: string) { // retrieve raw model data const todos = this.model.get(); // mutate model data todos.forEach(t => { if (t.id === id) { t.done = !t.done; } }); // set new model data (after mutation) this.model.set(todos); } }
Use service in your component. Import and inject service into components constructor. Subscribe to services data in template todosService.todos$ | async or explicitly this.todosService.todos$.subscribe(todos => { /* ... */ }) import { Component, OnInit, OnDestroy } from '@angular/core'; import { Subject } from 'rxjs'; import { TodosService, Todo } from './todos.service'; @Component({ selector: 'ngx-model-todos', templateUrl: ` /* ... */ <h1>Todos ({{count}})</h1> <ul> <!-- template subscription to todos using async pipe --> <li *ngFor="let todo of todosService.todos$ | async" (click)="onTodoClick(todo)"> {{todo.name}} </li> </ul> `, }) export class TodosComponent implements OnInit, OnDestroy { private unsubscribe$: Subject<void> = new Subject<void>(); count: number; constructor(public todosService: TodosService) {} ngOnInit() { // explicit subscription to todos to get count this.todosService.todos .pipe( takeUntil(this.unsubscribe$) // declarative unsubscription ) .subscribe(todos => this.count = todos.length); } ngOnDestroy(): void { // for declarative unsubscription this.unsubscribe$.next(); this.unsubscribe$.complete(); } onTodoClick(todo: Todo) { this.todosService.toggleTodo(todo.id); } }
make sure you're using this in project generated with Angular CLI.
install dependency with npm i -D @angular-extensions/schematics
generate model services with ng g @angular-extensions/schematics:model --name path/my-model
or with ng g @angular-extensions/schematics:model --name path/my-model-collection --items form model of collection of items
add your own model service methods and tests
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page