当前位置: 首页 > news >正文

网站备案信息批量查询中华南大街网站建设

网站备案信息批量查询,中华南大街网站建设,政务网站建设及管理,网站开发 只要完全基于redux的ngrx方案#xff0c;我们看看在angular中如何实现。通过一个简单的计数器例子梳理下整个流程 一 安装 #xff1a;npm i ngrx/store 这里特别要注意一点#xff1a;安装 ngrx/store的时候会出现和angular版本不一致的问题 所以检查一下angular/core的版本…完全基于redux的ngrx方案我们看看在angular中如何实现。通过一个简单的计数器例子梳理下整个流程 一 安装 npm i  ngrx/store 这里特别要注意一点安装 ngrx/store的时候会出现和angular版本不一致的问题 所以检查一下angular/core的版本和ngrx/store的版本是否一致如果不一致升级angular ng update angular/core17.0.0 --force。最好是删除node_modules目录重新下载。保证安装正常版本一致 二 创建store目录并且创建如下几个文件 1actions.ts (2) reducers.ts (3)  state.ts //state.tsexport interface AppState{count:number; } //actions.ts export const INSCRESINSCRES export const DESCRESDESCRES export const RESETRESET//reduces:import {Action} from ngrx/store import {INSCRES,DESCRES,RESET} from ./actionsconst initalState0; export function counterReducer(state:numberinitalState,action:Action){switch(action.type){case INSCRES:return state1;case DESCRES:return state-1case RESET:return 0default:return state}} (4) 页面中注入注意angular中使用store和react稍有不同。没有createStorereducer然后根组件注入的过程而是在具体页面里直接注入到constructor中我们以news页面为例 import { Component, ElementRef, ViewChild } from angular/core; import {INSCRES,DESCRES,RESET} from ../../store/reducer import {Store,select} from ngrx/store import { Observable } from rxjs;interface AppState{count:number }Component({selector: app-news,templateUrl: ./news.component.html,styleUrls: [./news.component.less] })export class NewsComponent {count:Observablenumberconstructor(public http:HttpClient,private store:StoreAppState){let streamstore.pipe(select(count))stream.subscribe(res{console.log(res:,res)})this.countstore.pipe(select(count))}increasement(){this.store.dispatch({type:INSCRES})}decreasement(){this.store.dispatch({type:DESCRES})}reset(){this.store.dispatch({type:RESET})}}然后在具体的页面中使用count button (click)increasement()增加increase/buttondivcounter {{count | async }}/divbutton (click)decreasement()减少increase/buttonbutton (click)reset()reset counter/button 整体来看和react中使用redux并没有太大的差异。唯一的差异就是在react中需要定义storelet storecreateStore(state,)angular中直接通过在页面中注入的方式完成。 二actions也可以是函数我们可以改造下actions //actions :注意这里需要用Injectable import {Injectable} from angular/coreexport const INSCRESINSCRES export const DESCRESDESCRES export const RESETRESETInjectable() export class CountAction{add(){return {type:INSCRES}}} 此时我们需要向app.moudule.ts中作相应修改 import { NgModule } from angular/core; import { BrowserModule } from angular/platform-browser;import {CountAction} from ./store/actionsimport { AppComponent } from ./app.component; import { NZ_I18N } from ng-zorro-antd/i18n; import { zh_CN } from ng-zorro-antd/i18n;import { HomeComponent } from ./pages/home/home.component; import { AppRouteModule } from ./app-route.module;import { StoreModule } from ngrx/store;registerLocaleData(zh);NgModule({declarations: [AppComponent,LayoutComponent,HomeComponent,],providers: [{provide:CountAction},{ provide: [NZ_I18N, UrlSerializer], useValue: zh_CN },{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptorInterceptor, multi: true },],bootstrap: [AppComponent],imports: [BrowserModule,FormsModule,AppRouteModule,StoreModule.forRoot({count:counterReducer}, {}),] }) export class AppModule { }注意这里我们给providers添加了counterAction以便在所有页面都可以注入countActions 回到页面本身 import { Component, OnInit } from angular/core; import { Observable, Observer } from rxjs; import{CountAction} from ../../store/actions import {Store,select} from ngrx/storeinterface AppState{count:number }Component({selector: app-home,templateUrl: ./home.component.html,styleUrls: [./home.component.less] }) export class HomeComponent {count:Observablenumberconstructor(private store:StoreAppState,private action:CountAction){this.countthis.store.pipe(select(count))increasement(){this.store.dispatch(this.action.add())}}这里逻辑的实现和之前一致唯一的区别就是我们countAction直接注到了counstor里然后在具体的执行函数中直接actiions的方法。
http://www.pierceye.com/news/544421/

相关文章:

  • 德阳建设局官方网站能去百度上班意味着什么
  • 网站推广临沂企业seo策划方案优化案例
  • 河北建设厅注册中心网站网站策划书模板大全
  • 嘉兴建设教育网站培训中心网站wordpress有哪些弹窗插件
  • 石家庄网站seo外包无锡 做网站
  • 江西中慧城乡建设开发公司网站修复WordPress图片上传错误
  • 冠县网站设计做网站优化找谁
  • 网站的建设公司哪个好推广线上渠道
  • 网站建设方向论文提纲安徽鑫华建设有限公司网站
  • 哪个网站上门做护肤优秀建筑案例分析
  • 建立网站ftp刷排名seo软件
  • 网站pv是什么app开发入门基础教程
  • 开发网站的可行性the7企业中 英文wordpress模板
  • 晋城网站设计重庆小程序商城开发
  • 找人做网站被骗能立案吗阿里云专有网络做网站
  • 做别人一摸一样的网站犯法吗买一个网站多少钱
  • 网站建设介绍书网站转换率
  • 云浮各类免费建站商业街网站建设方案
  • 注册网站怎么注册不了网站诊断示例
  • 打电话沟通做网站美食网页模板免费下载
  • 网站可以做库存吗表白网页在线生成网站
  • wordpress全站301网络设计项目
  • 新建网站二级网页怎么做手机建行网站
  • 手机编辑WordPress博客唐山seo推广公司
  • 网站建设祥云平台高明网站设计案例
  • 做网站比较大的公司黑客入侵网站怎么做
  • 汕头网站建设哪里找网站建设找哪家好
  • 怎么做公司的宣传网站免费优化
  • 网站数据库模板下载中牟网络推广公司
  • 营销型网站有什么特点域名解析错误无法上网