小编Rav*_*vta的帖子

是否有任何文件/类保存每个键盘事件的常量?

在角度中,我将数据与主机侦听器绑定,如下面的代码

@HostListener('window:keyup', ['$event'])
onKeyUp(event: KeyboardEvent) {
  if (event.keyCode === 13) {
    this.onEnterClicked(event);
  }
}
Run Code Online (Sandbox Code Playgroud)

在这段代码中,我想13Keycode.ENTER替换。但是没有可用的类来保存 Angular 和 JavaScript 中每个键的常量。

那么我还缺什么课吗?如果不是,那么为什么 javascript 或 Angular 没有在一处定义常量?

javascript angular

9
推荐指数
1
解决办法
9688
查看次数

如何处理Angular 7中的连接丢失页面?

我想要的是,如果网络不可用,并且用户尝试导航到下一页,那么ConnectionLostComponent就在那里.

但是,如果没有网络,用户不采取任何行动意味着不导航到第二页.那么不应该有一个连接丢失的页面.用户应该留在当前页面上.

为此,我已经实现了canActivate guard作为以下代码:

@Injectable({
  providedIn: 'root'
})
export class NetworkGuard implements CanActivate {
  constructor(private router: Router, private network: NetworkService) {
  }

  canActivate(next: ActivatedRouteSnapshot,
              state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
    if (window.navigator.onLine) {
      return true;
    } else {
      if (!this.isConnectionLostComponent()) {
        this.router.navigate(['/connection-lost'], {skipLocationChange: true});
      }
      return false;
    }
  }

  private isConnectionLostComponent() {
    // check whether connection lost component is added on not
    return this.network.isActive;
  }
}
Run Code Online (Sandbox Code Playgroud)

除了一个条件外它工作正常.也就是说,如果我从浏览器单击后退或前进,它的更新URL connection-lost地址栏 …

javascript guard web angular

7
推荐指数
2
解决办法
952
查看次数

投影 JavaScript 对象字段的最佳方法是什么?

我必须将 javascript 的一些字段投影到新对象。

例如我有一个下面的对象

var obj = { fn : 'Abc', 
            ln : 'Xyz', 
            id : 123, 
            nt : 'Note', 
            sl : 50000}
Run Code Online (Sandbox Code Playgroud)

我想要包含的新对象 fn and id

var projectedObj = { fn : 'Abc', id : 123 }
Run Code Online (Sandbox Code Playgroud)

基于投影

var projection = { fn : 1, id : 1 }
Run Code Online (Sandbox Code Playgroud)

像这样的东西

var projectedObj = project(obj, projection);
Run Code Online (Sandbox Code Playgroud)

那么什么是最好的方法或优化的方法来做到这一点。

javascript optimization ecmascript-5 ecmascript-6

6
推荐指数
1
解决办法
3763
查看次数

从角度2中删除历史记录中的组件

如何限制组件在背压时加载.实际上我有三个组件A(正常组件),B(LoginComponent)和C(Otp验证组件).我在某个按钮点击时从A路由到组件B,从B到C路由到组件B以验证用户.现在在对组件C进行验证之后,我想回到组件'A',并希望从历史记录中删除组件'B'和'C',以便在从浏览器返回时不加载'B'(LoginComponent)和'C'再次.那怎么能在angularjs 2中做到这一点.

typescript angular2-routing angular-component-router angular-components angular

3
推荐指数
1
解决办法
4072
查看次数

Material-UI:不支持带有网格对齐的非无单位行高。使用无单位行高代替

在许多 ReactJs 项目中,其中之一抛出以下错误:

Error: Material-UI: unsupported non-unitless line height with grid
alignment. Use unitless line heights instead.
Run Code Online (Sandbox Code Playgroud)

在定义 lineHeight 时px,下面是我的代码:

const breakpoints = createBreakpoints({});

let theme = createMuiTheme({
     typography: {
        allVariants: {
            fontFamily
        },
        h1: {
            fontWeight: 600,
            fontSize: 26,
            lineHeight: '32px',
            [breakpoints.down("sm")]: {
                fontSize: 18,
                lineHeight: '26px',
            }
        },
        h2: {
            fontWeight: 600,
            fontSize: 20,
            lineHeight: 28 / 20
        },
        h3: {
            fontWeight: 600,
            fontSize: 16,
            lineHeight: '22px',
            [breakpoints.down("sm")]: {
                fontSize: 14,
                lineHeight: '20px',
            }
        }
    } …
Run Code Online (Sandbox Code Playgroud)

css reactjs material-ui

1
推荐指数
1
解决办法
2689
查看次数

如何永久更改vim编辑器的默认选项?

我正在使用vimeditor 并且想要编辑vim editor提供的一些默认选项。

N+G(5G) 移动到第 n 行,但我希望 N+Enter 移动到第 n 行

同样地:

^想改成s

$想改成e

等等

unix linux vim shell command-line

0
推荐指数
1
解决办法
2676
查看次数