🖌️
ngxs
  • 介绍
  • 入门
    • 为什么使用ngxs
    • 安装
  • 概念
    • 介绍
    • 存储(Store)
    • 动作(Actions)
    • 状态(State)
    • 选择(Select)
  • 高级
    • 动作处理程序
    • 动作的生命周期
    • 取消
    • 组合
    • 错误处理
    • Ivy迁移指南
    • 延迟加载
    • 生命周期
    • 映射子状态
    • 元归约器
    • 优化选择器
    • 选项
    • 共享状态
    • 状态令牌
    • 状态操作
    • 子状态
  • 菜单
    • 认证
    • 缓存
    • NGXS的组件事件
    • 防抖动动作
    • 动态插件
    • 不可变数据助手
    • 设计指南
    • 单元测试
  • 插件
    • 介绍
    • CLI
    • Logger
    • Devtools
    • Storage
    • Forms
    • Web Socket
    • Router
    • HMR
  • NGXS实验室
    • 介绍
  • 社区
    • FAQ
    • 资源
    • 贡献者
    • 贡献
    • 赞助商
  • 变更日志
Powered by GitBook
On this page
  • Migration Overview
  • Changes You Have To Do

Was this helpful?

  1. 高级

Ivy迁移指南

Migration Overview

The Angular team has worked hard to ensure Ivy is as backwards-compatible with the previous rendering engine ("View Engine") as possible. Unfortunately, some changes have to be made so that NGXS and Ivy can function together seamlessly.

In Ivy, all provided or injected tokens must have @Injectable() decorator (previously, injected tokens without @Injectable() were allowed if another decorator was used, e.g. pipes). In our case the @State() decorator was used.

Changes You Have To Do

All states are providers, you don't care about their initialization as NGXS does it for you underneath. A typical state looks like this:

import { State } from '@ngxs/store';

@State<string[]>({
  name: 'countries',
  defaults: ['USA', 'Mexico', 'Canada']
})
export class CountriesState {}

As CountriesState is a provider and Ivy requires to decorate all providers with the @Injectable() decorator, then the Ivy compatible code should look like this:

import { Injectable } from '@angular/core';
import { State } from '@ngxs/store';

@State<string[]>({
  name: 'countries',
  defaults: ['USA', 'Mexico', 'Canada']
})
@Injectable()
export class CountriesState {}

Note: you don't have to set providedIn to root on the @Injectable() decorator.

Previous错误处理Next延迟加载

Last updated 4 years ago

Was this helpful?