美文网首页SAP
SAP 电商云 Spartacus UI 里如何捕捉语言设置的更

SAP 电商云 Spartacus UI 里如何捕捉语言设置的更

作者: _扫地僧_ | 来源:发表于2021-12-16 09:05 被阅读0次

    我们知道在 SAP 电商云 Spartacus UI 里,用户可以通过下拉菜单更改当前访问 site 的语言:

    监控语言变化的代码:

    this.subscription.add(
          this.languageService
            .getActive()
            .subscribe((isoCode: string) =>
              this.setDirection(
                this.winRef.document.documentElement,
                this.getDirection(isoCode)
              )
            )
        );
    

    这里的 get active,拿的其实是 active language:


    从 ngrx store 里读取语言:


    切换语言时发生了什么事情?

    找到触发源:


    在 Angular UI 里找到了 select 控件的 change 事件的响应处理逻辑:

    等号右边是一个表达式:active = $event.target.value;

    active 就是 Component 的属性,将 $event 的 target 的 value 字段值(即用户当前选中的语言)赋给 Component active 属性。


    active 是 Component 的属性。

    Component 将控制权交给 service:


    根据不同的 context 拿到 service:


    精髓在于,返回的是 Observable 对象:

    等到 subscribe 调用时才触发:


    更多Jerry的原创文章,尽在:"汪子熙":


    相关文章

      网友评论

        本文标题:SAP 电商云 Spartacus UI 里如何捕捉语言设置的更

        本文链接:https://www.haomeiwen.com/subject/kprjtrtx.html