小编ano*_*ous的帖子

如何在角度6中导入rxjs计时器?

我尝试在我的角度6项目中导入rxjs计时器

import { timer } from 'rxjs/observable/timer';
Run Code Online (Sandbox Code Playgroud)

我也尝试过,

Rx.Observable.timer(200, 100)
Run Code Online (Sandbox Code Playgroud)

它们不起作用

这是关于plunker的代码

angular rxjs6

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

angular的@input vs viewchild用于将数据从父级发送到子级组件

我已经以一种形式多次实现了相同的组件。我必须将数据从父组件发送到子组件。我知道可以通过@input或viewchild来实现。一个使用另一个的性能问题是什么?我什么时候应该使用viewchild或input?

angular

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

如何以编程方式单击材质元素?

我可以通过编程方式单击带有 elementref 的按钮元素,但如果按钮是材质按钮,则它不起作用

@ViewChild('findButton') findButton: ElementRef;
  clicked() {
  console.log('clicked');
}
ngOnInit() {
  this.findButton.nativeElement.click()
}
Run Code Online (Sandbox Code Playgroud)

并在模板中,

<div class="example-button-row">
  <button #findButton (click)="clicked()" mat-raised-button color="primary">Primary</button>
</div>
Run Code Online (Sandbox Code Playgroud)

mat-raised-button 属性造成了这个问题。这是stackblitz 上的代码

angular

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

垫选择内的模板出口不起作用

我试图在带有 template-outlet 的 mat-select 中传递 #tmp,但无法显示选择选项。下面是我的代码和 stackblitz 的链接

    <mat-form-field>
        <mat-select 
           [ngModel]="selectedFoods" 
           (ngModelChane)="selectedFoods" placeholder="Favorite food" multiple>
        <ng-container *ngFor="let food of allfoods"
            [ngTemplateOutlet]="tmp"
            [ngTemplateOutletContext]="{ $implicit: food}">
        </ng-container>
        </mat-select>
    </mat-form-field>
    <ng-template #tmp let-food>
      <mat-option [value]="food.value">
        {{food.viewValue}}
      </mat-option>
    </ng-template>
Run Code Online (Sandbox Code Playgroud)

https://stackblitz.com/edit/angular-mat-select-with-ngmodel-mujorn?embed=1&file=app/select-overview-example.ts

angular angular-content-projection

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

如何将新表单控件添加到嵌套表单组?

我有这个表单组:

this.form = fb.group({
  'teacher': [''],
  'schools': fb.array([
    fb.group({
      'school_name': [''],
      'school_description': [''],
    })
  }) 
});
Run Code Online (Sandbox Code Playgroud)

问题是:

如何通过函数school_cityFormArray编程方式将新表单控件(命名)添加到特定*组?

angular2-forms angular angular-reactive-forms

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

使用新 Set 删除数组中的重复项会出现错误

我正在尝试使用 new Set 删除数组中的重复项给出错误“new Set(names).slice is not a function”

const names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
const uniq = [ ...new Set(names) ];
console.log(uniq);
Run Code Online (Sandbox Code Playgroud)

这是stackblitz上的代码

javascript typescript spread-syntax

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

邮递员上的 POST 请求未完成

使用 GET 方法的路由有效,但使用 POST 方法的路由无效。邮递员继续奔跑,没有回复。

这是我尝试过的,

import * as hapi from "@hapi/hapi";
const init = async () => {
    const server: hapi.Server = new hapi.Server({
        port: 3000,
        host: 'localhost'
    });

   server.route({
        method: 'POST', // if you change it to GET, it works
        path: '/test',
        handler: function (request, h) {
            const payload = { username: 'testUserNames'};
            return payload.username;
        }
    });

    await server.start();
    console.log('Server running on %s', server.info.uri);

}

process.on('unhandledRejection', (err) => {
    console.log(err);
    process.exit(1);
});

init();
Run Code Online (Sandbox Code Playgroud)

可能是什么问题?我哪里错了?

node.js hapi hapi.js

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