Angular2材质sidenav-动态更改rtl/ltr方向 [英] Angular2 material sidenav - changing rtl/ltr direction dynamically

查看:82
本文介绍了Angular2材质sidenav-动态更改rtl/ltr方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据用户的语言选择动态更改布局,并即时从LTR切换到RTL.

I'm trying to change my layout dynamically according to users' language selection and switch from LTR to RTL on the fly.

我正在使用Angular 2 rc6,材料2.0.0-alpha.9-3

I'm using Angular 2 rc6, material 2.0.0-alpha.9-3

页面加载时看起来很像rtl或ltr. 但是,当从应用程序内部对其进行动态更改时(请参见plunker),方向会发生变化,但是生成的元素md-sidenav-content的计算的margin-right和margin-left的计算错误.

It looks like when the page is loaded, it works perfectly with either rtl or ltr. However, when it's changed dynamically from within the app (see plunker), the direction changes but the generated element md-sidenav-content has a miscalculated margin-right and margin-left.

进一步挖掘,我设法看到_dir对象具有一个eventEmitter,该事件应监视_dir的更改事件并重新计算边距

Digging further, I managed to see that the _dir object has an eventEmitter that should watch for on change events of _dir and recalculate the margins

@ angular/material/sidenav/sidenav.js:

@angular/material/sidenav/sidenav.js:

_dir.dirChange.subscribe(function () { return _this._validateDrawers(); });

但是在动态更改方向时永远不会调用它. 虽然,_dir首次加载页面时保留正确的值,无论是ltr还是rtl.

But it's never called when changing the direction dynamically. Although, _dir holds the correct value when page is being loaded for the first time, whether its ltr or rtl.

最后,这是一个用来证明这种行为的工具:

Finally, here's a plunker to demonstrate the behaviour:

http://plnkr.co/edit/o8lXWC?p=preview

我怀疑我没有正确使用_dir,但是无法弄清楚什么是正确的方法.

I suspect I'm not using _dir correctly but not managed to figure out what's the right way to do it.

推荐答案

看看源代码Dir指令

@Input('dir') _dir: LayoutDirection = 'ltr';

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆