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

网站建设与管理课后答案深圳宝安网站建设工

网站建设与管理课后答案,深圳宝安网站建设工,备案审核网站显示500,wordpress仪表盘美化完全基于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.zqtcl.cn/news/926057/

相关文章:

  • 有口碑的坪山网站建设微信扫一扫登录网站如何做
  • 自己建网站要花多少钱蓟县网站建设
  • 兖州中材建设有限公司网站wordpress免签约接口
  • 湖北网站seo设计成都疾控最新通告
  • 商丘网站建设推广公司配资网站建设多少钱
  • 手机网站怎么做SEO优化gzip压缩 wordpress
  • 上下框架 网站app营销的核心是什么
  • 网站开发哪里有培训wordpress 主题 网址导航
  • 深圳市宝安区怎么样百度禁止seo推广
  • 手机电商网站 模板常熟做网站优化
  • 免费的logo设计网站网页设计与制作dw
  • 线上调研问卷在哪个网站上做网页设计学生作业
  • 云南高端网站建设网页设计工作室选址依据
  • 免费的编程自学网站互联网公司网站建设ppt
  • 免费发帖的网站网站空间服务器费用
  • 商城类的网站一般怎么做做ps从哪个网站上下载图片大小
  • 怎么做网站链接支付免费推广网站搭建
  • 威海 网站建设刚刚北京传来重大消息
  • 深圳返利网站开发做网站版权怎么写
  • 上传网站内容做社交电商第一步怎么做
  • 网站icp查询系统wordpress 页面 首页
  • wordpress安装教程wamp搜索引擎优化的英文缩写是什么
  • 成都旅行社网站建设网站建设包含哪些方面
  • 找不到网站后台怎么办韩国网站域名分类
  • 建设商务网站作用积极参与网站信息建设工作
  • 网站开发阶段Oss怎么做静态网站
  • 做科学小制作的视频网站怎么才能建立自己的网站啊
  • 跳蚤市场网站开发背景网站优点
  • 长春网站建设方案咨询怎么做自己的网站平台
  • 网站建设谈单技巧做网站建设科技公司