小编Max*_*lid的帖子

RxJs Observables嵌套订阅?

什么是简化以下代码示例的方式?我找不到合适的操作员..任何人都可以举一个简短的例子吗?

this.returnsObservable1(...)
  .subscribe(

    success => {

      this.returnsObservable2(...)
        .subscribe(

          success => {

            this.returnsObservable3(...)
              .subscribe(

                success => {
                   ...
                },
Run Code Online (Sandbox Code Playgroud)

subscribe observable rxjs

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

Angular2探索canActivate Guard中的已解决数据?

是否可以在canActivate防护中访问路径(-Resolver)的已解析数据.目前我可以通过访问组件中已解析的数据

ngOnInit() {
    this.route.data
        .subscribe((data: { example: Array<Object> }) => {
            this.example = data.example;
            console.log('example resolver', this.example);
        });
}
Run Code Online (Sandbox Code Playgroud)

我怎么能在canActivate后卫中管理它?这不起作用:

constructor(private route: ActivatedRoute) {}

canActivate(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot,
): boolean {

    this.route.data
        .subscribe((data: { example: Array<Object> }) => {
            this.example = data.example;
            console.log('example resolver', this.example);
        });
}
Run Code Online (Sandbox Code Playgroud)

router guard resolver angular

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

Angular2使用*ngIf和焦点指令?

在我的应用程序中,我尝试放置一个按钮,显示/隐藏带有布尔组件属性的输入字段.如果按钮显示输入,则应在输入上设置焦点.但它似乎不起作用.如果我删除input焦点指令工作正常.

我创造了一个显示我的意思的plunker.描述我的"问题"有点困难.

组件中的html

<input *ngIf="filterShow.options"
       [focus]="filterFocus.options"
       [(ngModel)]="filter.options">

<button type="button"
        (click)="setShowFilter('options')">
  focus
</button>
Run Code Online (Sandbox Code Playgroud)

setShowFilter()函数

private setShowFilter(filter: string) {
  this.filterShow[filter] = !this.filterShow[filter];

  /* reset filter */
  this.filter[filter] = "";

  this.filterFocus[filter].emit(true);
}
Run Code Online (Sandbox Code Playgroud)

focus.directive.ts

@Directive({
  selector: '[focus]'
})
export class FocusDirective implements OnInit {

  @Input('focus') focusEvent: EventEmitter<boolean>;

  constructor(private elementRef : ElementRef,
              private renderer   : Renderer   ) { }

  ngOnInit() {
    this.focusEvent.subscribe(event => {
      this.renderer
        .invokeElementMethod(this.elementRef.nativeElement, 'focus', []);
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

focus input angular-ng-if angular

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

组件销毁时的angular 5删除样式节点

我是否错了,或者当组件被销毁时,样式节点是否会从文档的头部消失? https://github.com/juleskremer/angular/commit/385ed90ac373c0347ea88fe38685405c01ba1a58

如果我将封装设置为"none",则为该组件添加的样式节点即使被销毁也会保留?

有没有办法在组件被销毁时删除样式节点?

styles encapsulation head angular

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

Angular2反应形式选择多个属性?

我在我的应用程序中使用以下代码与反应形式.

如果我取消注释该[multiple]行,则选择...选项不会将dformControl表单控件对象设置回状态INVALID.

dformControl.multiple顺便回来false.即使我将注释行更改为[multiple]="false",仍然切换回选择...选项不会将表单控件状态设置为INVALID.

<select class="form-control"
        [id]="dformControl.key"
        [formControlName]="dformControl.key"
        /*[multiple]="dformControl.multiple"*/>

  <option *ngIf="!dformControl.value"
          value="">
    Choose ...
  </option>

  <option *ngFor="let opt of dformControl.options"
          [value]="opt.value"
          [selected]="dformControl.value == opt.value">
    {{opt.label}}
  </option>

</select>
Run Code Online (Sandbox Code Playgroud)

forms select reactive angular

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

Angular2 TypeScript使用来自变量的类名动态创建新对象?

我试图开始某种工作:

export class SomeComponent {

  constructor() {

    let className: string = "TheClass";

    /* should be the same as .. = new TheClass() */
    let superSpecial = new className();

  }

}
Run Code Online (Sandbox Code Playgroud)

我还没有弄清楚该怎么做?有人可以帮我吗?

javascript class typescript

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

Angular4复制对象没有引用?

在组件内部,我尝试从可以在组件内部修改的服务中复制对象,但应该保留在服务中.

private test;

public ngOnInit(): {
  console.log(this.someService.test.someProperty) //'old'
  this.test = this.someService.test;

  //not working as well?!
  //this.test = Object.assign({}, this.someService.test);
  //this.test = Object.create(this.somerService.test);

  this.changeTest();
}

public changeTest(): void {
  this.test.someProperty = 'new';
}
Run Code Online (Sandbox Code Playgroud)

在init之后,this.test.someProperty以及this.someService.test.someProperty更改为new即使最后应该留下old

为什么会这样,以及如何只改变属性 this.test

copy reference object angular

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