小编und*_*ned的帖子

如何让Visual Studio代码在格式化代码中显示斜体字体?

如何配置VS代码以支持斜体样式,如此图片中所示?

我目前的设置:

{
  "editor.fontLigatures": true,
  "editor.fontFamily": "Operator Mono"
}
Run Code Online (Sandbox Code Playgroud)

fonts visual-studio-code

45
推荐指数
7
解决办法
3万
查看次数

这是什么:在可变的JS语法后签名?

在查看svelte库时,我在JS中遇到以下有效语法:

$: doubled = 6 * 2;
Run Code Online (Sandbox Code Playgroud)

起初,我认为它是特定于该库的,但是它可以在Chrome控制台上使用。这是什么语法?

可以是任何东西:

name: something = 6 * 2;
Run Code Online (Sandbox Code Playgroud)

javascript syntax svelte

14
推荐指数
3
解决办法
615
查看次数

Angular 2 测试 ng-content

我想知道是否有一种方法可以在ng-content不创建宿主元素的情况下进行测试?

例如,如果我有警报组件 -

@Component({
  selector: 'app-alert',
  template: `
    <div>
      <ng-content></ng-content>
    </div>
  `,
})

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [AlertComponent]
    })
      .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(AlertComponent);
    component = fixture.componentInstance;
  });

  it('should display the ng content', () => {

  });
Run Code Online (Sandbox Code Playgroud)

如何在ng-content不创建宿主元素包装器的情况下进行设置?

javascript angular

10
推荐指数
2
解决办法
5732
查看次数

RxJS skipWhile vs filter

skipWhile和过滤器运算符有什么区别?

const source = interval(1000);
const example = source.pipe(skipWhile(val => val < 5));
const subscribe = example.subscribe(val => console.log(val));


const source = interval(1000);
const example = source.pipe(filter(val => val > 5));
const subscribe = example.subscribe(val => console.log(val));
Run Code Online (Sandbox Code Playgroud)

javascript rxjs

10
推荐指数
3
解决办法
2902
查看次数

Angular CDK了解叠加位置系统

我真的想了解叠加位置参数,但没有任何运气.我也找不到任何关于这个主题的文档.

以下代码是什么意思?

const positions = [
  new ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' }),
  new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' })
];
this.positionStrategy = this._overlay.position()
.flexibleConnectedTo(this.getConnectedElement())
.withPositions(positions)
.withFlexibleDimensions(false)
.withPush(false);
Run Code Online (Sandbox Code Playgroud)

angular angular-cdk

9
推荐指数
3
解决办法
5812
查看次数

Angular onPush 不会从父级更新子属性

我有一个看起来像这样的子组件:

@Component({
  selector: 'app-child',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    {{text}}
  `
})
export class ChildComponent {
  @Input() text = '';

  constructor(public host: ElementRef) { }
}
Run Code Online (Sandbox Code Playgroud)

还有一个看起来像这样的父组件:

@Component({
  selector: 'app-parent',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `<ng-content></ng-content>`
})
export class ParentComponent {
  @ContentChild(ChildComponent) child: ChildComponent;

  constructor(private cdr: ChangeDetectorRef) { }

  ngAfterContentInit() {
    this.child.text = 'hello';
    this.child.host.nativeElement.addEventListener('click', () => {
      this.child.text = 'from click';
      this.cdr.detectChanges();
    });
  }
Run Code Online (Sandbox Code Playgroud)

第一次分配给text属性工作正常,但是当我单击按钮并尝试text再次更改属性时,什么也没有发生。

这很令人困惑,因为据我所知: 1. click 事件应该触发更改检测,并且 text 属性不同,因此应该已更新。2.我明确地打电话detectChanges(),这也应该检查我所知道的孩子们。

我错过了什么?

javascript angular

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

标签内的 HTML 按钮不会触发文件上传

我想使用标签来创建自定义文件输入:

    input[type="file"] {
        width: 0.1px;
        height: 0.1px;
        opacity: 0;
        overflow: hidden;
        position: absolute;
        z-index: -1;
    }
    
    section {
    	padding: 30px;
    	border: 1px solid lightgray;
    	width: 200px;
    	margin: 100px;
    }
    
    label {
        display: block;
    }
Run Code Online (Sandbox Code Playgroud)
    <section>
    	<label for="test">
    	    <input type="file" id="test">
    	    <button>Click me</button>
        </label>
    </section>
Run Code Online (Sandbox Code Playgroud)

但是,当我单击标签内的按钮时,它不会打开文件弹出窗口,只有当我单击标签外部时,它才起作用。我怎样才能做到这一点?

html javascript css

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

Typescript 抽象方法不继承参数类型

我有以下代码:

abstract class Foo<T extends { data: string }> {
  abstract doSomething(params: T): void;
} 


class Baz extends Foo<{ id: string; data: string }> {
   doSomething(params) {}
}
Run Code Online (Sandbox Code Playgroud)

我的期望是,在实现该doSomething方法时,它会自动推断出paramsas T,但它将其推断为any。我错了吗?

typescript

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

RxJS publishReplay与publishLast

我正在Angular应用程序中实现缓存HTTP结果.据我所知,下面的代码都有效,但是我需要知道它们是否完全相同,或者我错过了一些重要的东西?

publishLast

getPosts() {
    if( !this.posts$ ) {
      this.posts$ = this.http.get('api').publishLast().refCount();
      return this.posts$;
    }

    return this.posts$;
  }
Run Code Online (Sandbox Code Playgroud)

publishReplay

getPosts() {
  if( !this.posts$ ) {
    this.posts$ = this.http.get('api').publishReplay(1).refCount();
       return this.posts$;
  }

  return this.posts$;
}
Run Code Online (Sandbox Code Playgroud)

javascript rxjs

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

JS递归对象赋值

我了解到,当使用Object.assign()时,它只扩展顶级对象.我怎样才能深度扩展对象?例如,假设我有以下源对象:

const source = {
  id: 1,
  otherKey: {},
  params: {
    page: {
      a: 1,
      b: {}
    },
    data: {
      b: 1
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我这样使用Object.assign():

Object.assign({}, source, {
  params: {
    page: {
      a: 2
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

结果将是:

{
      id: 1,
      otherKey: {},
      params: {
        page: {
          a: 2
        }
      }
}
Run Code Online (Sandbox Code Playgroud)

如何以浅克隆方式保留params.data键和params.page.b键.

oldObject.params.data === newObject.params.data  // true
oldObject.params.page === newObject.params.page  // false
oldObject.params.page.b === newObject.params.page.b // true
Run Code Online (Sandbox Code Playgroud)

注意:此问题与如何深度合并而不是浅合并不同.那里的答案没有给出预期的结果.

检查此bin从上面的链接中获取答案.

javascript shallow-copy javascript-objects shallow-clone

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