小编Mon*_*sto的帖子

从 console.log 调用 webpack 捆绑的函数/类

是否可以从 Web Inspector 控制台访问导出的模块(ES6-> ES5 编译)?它们使用 webpack 捆绑在一起

我正在尝试调用 Session.setSessionInLocalStorage('test key', 'test object');

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;
/******/
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: …
Run Code Online (Sandbox Code Playgroud)

javascript console module export webpack

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

Angular2 单元测试选择下拉值

我有一个县下拉。有一个默认值。用户可以选择一个国家。更改时,它会将用户重定向到正确的国家/地区页面。哪个有效。

但是,我正在尝试对选择框中的默认值进行单元测试。但我一直将空字符串/值selectEl.nativeElement.value变为''. 任何人有任何想法为什么?

// locale-component.ts
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { cultures} from '../../../config/config';

@Component({
  selector: 'app-locale',
  templateUrl: './locale.component.html',
  styleUrls: ['./locale.component.scss']
})
export class LocaleComponent {

  cultures = cultures;

  constructor() {}

  onLocaleChange(locale) {
    const str = window.location.href.replace(new RegExp(`/${this.cultures.default}/`), `/${locale}/`);
    window.location.assign(str);
  }
}


  // locale.component.spec.ts

  beforeEach(() => {
    fixture = TestBed.createComponent(LocaleComponent);
    component = fixture.componentInstance;
    component.cultures = {
      default: 'en-ca',
      supported_cultures: [
        { "name": "United States", "code": …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing jasmine typescript angular

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

Jquery工具触摸水平仅禁用垂直触摸

我有jquery工具滚动...我喜欢它只为swipeLeft swipeRight实现触摸选项.

当我使用touch:true时,它也会在swipeUp/Down时旋转.

我按照这里的说明:

jQuery工具可滚动触摸禁用垂直滚动

和这里:

http://awardwinningfjords.com/2010/09/22/handling-touch-events-in-jquery-tools-scrollable.html

但似乎没有工作..任何想法?我的小提琴/演示在下面供参考

小提琴:http://jsfiddle.net/mmp2m/7/

演示:http://jsfiddle.net/mmp2m/7/show

谢谢

jquery scroll touch gesture swipe

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

Typescript import index.ts 不是模块

我正在尝试将 index.ts 导入到具有其他导入的子文件夹中。但我不断收到打字稿错误。

完整仓库: https: //github.com/Shavindra/webpack-react-sw

(5,32): error TS2306: File 'C:/../src/reducers/index.ts' is not a module.

我不太确定我在这里做错了什么。我使用的是 TS 2.4.1。我尝试重新启动计算机/VSCode,但似乎没有任何效果:-|

// ./src/reducers/counter.reducer.ts    
export const counterReducer = (state = 0, action) => {
  switch (action.type) {
    case 'INCREMENT':
      return state + 1;
    case 'DECREMENT':
      return state - 1;
    default:
      return state;
  }
};


// ./src/reducers/index.ts
export * from './counter.reducer';


// ./src/app.ts
import * as React from 'react';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { createStore } …
Run Code Online (Sandbox Code Playgroud)

javascript import export typescript reactjs

5
推荐指数
1
解决办法
2万
查看次数

NestJs CASL 基于用户属性和策略的授权守护

我正在尝试在 NestJS 和 CASL 中为列表/获取端点实现基于通用策略的防护。我正在关注此处的文档https://docs.nestjs.com/security/authorization#integrating-casl

一个用户可以属于多个组。我需要检查是否Article与任何用户组匹配的Books实体。并且仅当用户的组列表匹配且groupId允许用户读取它们Article.idBooks.id

但我无法得到它似乎正在工作

// User Object - from request.user after decoded from AuthGuard('jwt')

user = {
  groups: ['department-1', 'department-2']

}
Run Code Online (Sandbox Code Playgroud)
// Article Entity
export class Article extends UUIDBase {
  @Column({ nullable: false })
  groupId: string

  @Column({ nullable: true })
  description: string

  @Column({ nullable: true })
  name: string
}
Run Code Online (Sandbox Code Playgroud)
// Books Entity
export class Books extends UUIDBase {
  @Column({ nullable: false })
  groupId: string

  @Column({ nullable: true …
Run Code Online (Sandbox Code Playgroud)

javascript authorization typescript nestjs casl

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

typescript - 用于输入字符串的字符串文字类型

我有一个带有字符串文字类型保护的方法

type Status = 'new' | 'update' | 'close';

itemRequest(status: Status) { 
    itemService.subscribeToChanges(status) //third party library method
}
Run Code Online (Sandbox Code Playgroud)

我遇到的困难是这个第三方方法接受字符串而不是我的自定义字符串类型 Status

subscribeToChanges(status: string) 
Run Code Online (Sandbox Code Playgroud)

如何使我的字符串文字实际上是字符串类型以及何时传递给第三方方法。它明白它实际上是一个字符串吗?

javascript string typeliteral typescript

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

在加载ajax的内容中预加载图像

我正在使用这个脚本......

它将URL中特定#id的内容加载到当前页面,并为其设置动画...从页面侧面滑动...当用户单击链接时

一切都有效,除了图片需要时间加载......我尝试并努力将图像预加载器合并到此?所以所有内容加载在一起

function goTo(href) {

    var left = $(window).width();
    $('#id').css("left", left);

    $.ajax({
        url: href,
        success: function (data) {

            var content = $(data).find('#id').html();

            // Windows Load Function
            $(window).load(function () {

                $("#id").html(content).animate({
                    left: '0',
                }, 'fast');

                var title = $('#id').find('h1').text();
                $('head').find('title').text(title);

            });
        }
    });
}

// check for support before we move ahead

if (typeof history.pushState !== "undefined") {
    var historyCount = 0;

    // On click of link Load content and animate
    $('.access a').live('click', function () {

        var href = $(this).attr('href'); …
Run Code Online (Sandbox Code Playgroud)

ajax jquery html5 image

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

Angular Cli - SyntaxError: 'import' 和 'export' 可能只与 'sourceType: module' 一起出现

我正在尝试使用 angular cli 生成覆盖率报告。但是我不断收到以下错误。我不太确定这是 cli 错误还是 Karma.conf 的问题?ng test/npm test运行良好... 所以与代码覆盖选项有关吗?

    Error: Module build failed: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (3:0)
        at Parser.pp$5.raise (C:\Development\source\\node_modules\babylon\lib\index.js:4443:13)
        at Parser.pp$1.parseStatement (C:\Development\source\\node_modules\babylon\lib\index.js:1875:16)
        at Parser.parseStatement (C:\Development\source\\node_modules\babylon\lib\index.js:5795:22)
        at Parser.pp$1.parseBlockBody (C:\Development\source\\node_modules\babylon\lib\index.js:2262:21)
        at Parser.pp$1.parseTopLevel (C:\Development\source\\node_modules\babylon\lib\index.js:1772:8)
        at Parser.parse (C:\Development\source\\node_modules\babylon\lib\index.js:1667:17)
        at Object.parse (C:\Development\source\\node_modules\babylon\lib\index.js:7163:37)
        at Instrumenter.instrumentSync (C:\Development\source\\node_modules\istanbul-lib-instrument\dist\instrumenter.js:121:31)
        at Instrumenter.instrument (C:\Development\source\\node_modules\istanbul-lib-instrument\dist\instrumenter.js:176:32)
        at Object.module.exports (C:\Development\source\\node_modules\istanbul-instrumenter-loader\index.js:25:25),Module build failed: SyntaxError: 'import
    ' and 'export' may appear only with 'sourceType: module' (2:0)
        at Parser.pp$5.raise (C:\Development\source\\node_modules\babylon\lib\index.js:4443:13)
        at Parser.pp$1.parseStatement (C:\Development\source\\node_modules\babylon\lib\index.js:1875:16) …
Run Code Online (Sandbox Code Playgroud)

code-coverage typescript karma-jasmine angular-cli angular

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