小编yoo*_*ung的帖子

Typescript 中的类型推断与显式类型声明

我遇到过几个不同的代码实例,其中使用显式类型声明变量,即使推断类型很明显:

示例:loading: boolean = falsename: string = "John"count: number = 0等。

TSLint 更喜欢推断类型而不是显式类型,所以我想知道这只是一个文体问题吗?这些显式类型在运行时是否重要?

typescript angular

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

mat-chip选择事件发射器没有发射?

Plunkr:http://plnkr.co/edit/y4e4jS89gOxRKQOyUW2r?p =preview

我在mat-chip上使用selectionChange @Output来查看芯片选择的结果,但似乎eventEmitter没有触发芯片选择?

html的:

<mat-chip-list>
  <mat-chip (selectionChange)="changeSelected($event)">Papadum</mat-chip>
  <mat-chip (selectionChange)="changeSelected($event)">Naan</mat-chip>
  <mat-chip (selectionChange)="changeSelected($event)">Dal</mat-chip>
</mat-chip-list>

<p>Currently Selected: {{selected}}</p>
Run Code Online (Sandbox Code Playgroud)

.TS:

selected: string;

changeSelected(e) {
  console.log(e);
  this.selected = e.value;
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,单击选择时根本不会发出任何事件.这是一个仍在开发中的东西,还是选择意味着与我的想法不同?

angular-material2 angular

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

云功能(Firebase)-通过部分加载Firebase模块减少冷启动时间?

Firebase文档建议明智地管理依赖关系,这是减少冷启动时间的第一件事:https : //firebase.google.com/docs/functions/tips#use_dependencies_wisely

对于大多数Firebase功能,您可能会使用firebase-functionsfirebase-admin模块。

这是一个实用的示例函数:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

// Initialize the app in admin sdk
admin.initializeApp();

// Firestore timestamp support
admin.firestore().settings({timestampsInSnapshots: true});

exports.simpleFunction = functions.https.onCall((data, context) => {
    return admin.auth().getUserByEmail(data.email)
        .catch(() => {
            return Promise.reject(new https.HttpsError('not-found', 'User not found.'));
        })
        .then(userRecord => {
            return admin.firestore().collection('user').doc(userRecord.uid).get();
        })
});
Run Code Online (Sandbox Code Playgroud)

冷启动执行时间:Function execution took 7517 ms, finished with status code: 200 热启动时间:Function execution took 8 ms, finished with status code: 200

如图所示,对该功能的测试具有〜7.5秒的冷启动启动时间(尽管显着的热响应时间)。尽管有许多因素可以解释为什么会出现这种情况,但是一个原因可能是加载 …

javascript node.js firebase google-cloud-functions

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

Angular 单元测试 - 在 ViewChild 中引用存根/模拟指令

如何存根/模拟读取为 的指令/组件ViewChild

例如,使用 angular.io 中的简单指令:

@Directive({
  selector: '[appHighlight]'
})
export class HighlightDirective {
  constructor() { }
}
Run Code Online (Sandbox Code Playgroud)

假设我正在测试并将使用AppComponent读取为:HighlightDirectiveViewChild

@ViewChild(HighlightDirective) theHighlightDirective: HighlightDirective
Run Code Online (Sandbox Code Playgroud)

存根指令是:

@Directive({
  selector: '[appHighlight]'
})
export class StubbedHighlightDirective {
  constructor() { }
}
Run Code Online (Sandbox Code Playgroud)

由于组件正在尝试读取,即使您在单元测试中HighlightDirective声明,也将是。StubbedHighlightDirectivetheHighlightDirectiveundefined

例子:

it('HighlightDirective is defined', () => {
    // This test fails
    expect(component.theHighlightDirective).toBeDefined();
});
Run Code Online (Sandbox Code Playgroud)

如果您忽略 tslint 中的某些内容或使用as关键字,则可以解决此问题:

Version 1: Just ignore some things in tslint so compiler doesn't complain
it('HighlightDirective is defined', () …
Run Code Online (Sandbox Code Playgroud)

unit-testing jasmine viewchild angular

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