小编Chr*_*ian的帖子

Angular2时钟每秒更新一次

我按照英雄之旅教程,我现在正在修改项目.我的项目将有很多时钟和计时器,我的第一个任务是制作一个显示UTC时间的时钟.使用MomentModule,我可以显示页面加载的时间:

<p>{{ myDate | amDateFormat: 'ddd Do HH:mm:ss' }}</p>
Run Code Online (Sandbox Code Playgroud)

但是,它并不像我想要的那样每秒更新一次.

我的DashboardComponent看起来像这样:

export class DashboardComponent implements OnInit {
    heroes: Hero[] =[];
    myDate: Date;

    constructor(private heroService: HeroService) {}

    ngOnInit(): void {
        this.heroService.getHeroes()
            .then(heroes => this.heroes = heroes);

        this.utcTime();
    }

    utcTime(): void {
        setInterval(function() {
            this.myDate = new Date();
            console.log(this.myDate); // just testing if it is working
        }, 1000);
    }
}
Run Code Online (Sandbox Code Playgroud)

首先,创建新的Date()是个好主意; 每一秒?无论哪种方式,有没有办法通过像观察或类似的东西每秒更新我的视图中的时间?就像我说的那样,当我完成时,我的页面上会有很多计时器和时钟.谢谢!

angular-moment angular

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

授权的 Javascript Origins 通配符替代方案

我们最近在我们的平台上引入了 Google 单点登录。除了一个问题外,它运行良好。我们所有的开发分支都会自动分配一个类似于 的 url https://{branch-name}.ourdomain.com。截至目前,我们必须为每个环境手动添加授权源,这对我们来说是不可扩展的。

是否有一种解决方案(例如我们可以在部署过程中使用的 API),不需要我们从同一源为所有分支进行授权并进行重定向舞蹈?理想的解决方案是通配符解决方案,我们可以将其添加https://*.ourdomain.com为授权来源,但这在 Google Cloud Platform 中似乎不允许。

google-sso google-cloud-platform

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

Angular2测试"找不到名字'HTMLElement'"

我正在尝试将测试引入我现有的项目中,但我仍然遇到同样的错误,我认为这会阻止我运行测试.我得到的错误是

错误在.../src/app/dashboard.component.spec.ts(15,13):找不到名称'HTMLElement'.)

Chrome 57.0.2987(Mac OS X 10.12.3):执行4个成功中的4个(7.24秒/ 6.55秒)

我的dashboard.component.spec.ts看起来像这样:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';

import { DashboardComponent } from './dashboard.component';
import { ExchangeService } from './exchange.service';

describe('DashboardComponent (templateUrl)', () => {

    let comp: DashboardComponent;
    let fixture: ComponentFixture<DashboardComponent>;

    let spy: jasmine.Spy;
    let de: DebugElement;
    let el: HTMLElement; // how does this work...?
    let exchangeService: ExchangeService; // the actual injected service

    const testExchange = 'New York Stock …
Run Code Online (Sandbox Code Playgroud)

jasmine karma-jasmine angular2-testing angular

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