小编Aje*_*jey的帖子

时刻js将毫秒转换为日期和时间

我的当前时间以毫秒为单位 - 1454521239279

如何将其转换为2016年2月3日和晚上11点10分?

javascript momentjs

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

Angular 2通过[class.className]绑定添加多个类

虽然添加单个类以这种方式运行良好 -

[class.loading-state]="loading"

但是我如何添加多个类Ex如果loadingtrue添加类 -"loading-state" & "my-class"

我如何通过 [class] binding

javascript binding angular

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

如何在悬停时向元素添加类?

如何在div上盘旋时将类添加到div.

模板 -

<div class="red">On hover add class ".yellow"</div>
Run Code Online (Sandbox Code Playgroud)

零件 -

import {Component} from 'angular2/core';

@Component({
  selector: 'hello-world',
  templateUrl: 'src/hello_world.html',
  styles: [`
    .red {
      background: red;
    }

    .yellow {
      background: yellow;
    }

  `]
})
export class HelloWorld {
}
Run Code Online (Sandbox Code Playgroud)

演示

[注意 - 我特别想添加一个新类,而不是修改现有的类]

叹!这是一个正常的用例,我还没有看到任何直接的解决方案!

angular2-template angular

27
推荐指数
3
解决办法
4万
查看次数

Angular2 zone.run()vs ChangeDetectorRef.detectChanges()

假设我function noificationHandler()在我的service.ts中有一个超出angular的上下文. noificationHandler()由第三方调用并noificationHandler()基本上使用数组并将数组发送到已订阅其服务的组件.

service.ts

    public mySubject: Subject<any> = new Subject();
    public myObservable = this.mySubject.asObservable();

    constructor() {
       this.registry.subscribe("notification.msg",this.noificationHandler.bind(this));
    }

    noificationHandler(data) {
       this.publishUpdate(data)
    }

    publishUpdate(data) {
       this.mySubject.next(data);
    }
Run Code Online (Sandbox Code Playgroud)

component.ts

constructor(private service: myService) {
    this.service.myObservable.subscribe(list => {
        this.list = list;
    });
}
Run Code Online (Sandbox Code Playgroud)

此时^^^模板未使用新数据更新

由于"notification.msg"它位于角度区域之外,因此("notification.msg")在调用此事件时不会运行角度变化检测.

现在有两种方法可以调用变化检测.

1)通过包装noificationHandler()angular的zone.run()的内部

 this.registry.subscribe("a2mevent.notification.msg", this.ngZone.run(() => this.noificationHandler.bind(this)));
Run Code Online (Sandbox Code Playgroud)

2)通过单独要求组件检测变化

constructor(private service: myService, private ref: ChangeDetectorRef) {
    this.service.myObservable.subscribe(list => {
        this.list = list;
        this.ref.detectChanges(); // <==== manually invoking change detection
    }); …
Run Code Online (Sandbox Code Playgroud)

javascript angular2-changedetection angular

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

Angular 2有条件地在组件中注入服务

例如:

我有2项服务

1)one.service.ts

2)two.service.ts

我有一个组件 - dashboard.component.ts

import { Component, ViewEncapsulation, Inject } from '@angular/core';
import { OneService } from '../services/one.service';
import { TwoService } from '../services/two.service';

@Component({
  selector: 'dashboard',
  encapsulation: ViewEncapsulation.Emulated,
  styleUrls: ['./dashboard.less'],
  templateUrl: './dashboard.html'
})
export class DashboardComponent {
    constructor() {
       // Here how do I get service instance based on some this condition.
         if(true) {
             /* Service **one.service.ts** to be injected */
         } else {
             /* Service **two.service.ts** to be injected */    
         }

    }
}
Run Code Online (Sandbox Code Playgroud)

javascript dependency-injection angular2-services angular

13
推荐指数
1
解决办法
5681
查看次数

HTML字符实体引用用于最大化和最小化

我想知道是否有&times;最大化或最小化的东西?

&times; 输出一个X,同样有什么内置可用于最大化和最小化?

html html-entities

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

在页面加载时触发CSS3转换

我试图通过CSS3宽度转换实现页面加载的加载效果.这是演示.

HTML

<div class="skill-bar">
    <span class="w70"></span>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

.skill-bar {
    width: 57%;
    float: left;
    height: 11px;
    border-radius: 5px;
    position: relative;
    margin: 6px 0 12px 0;
    border: 2px solid #00edc2;
}
.skill-bar span {
    background: #00edc2;
    height: 7px;
    border-radius: 5px;
    display: inline-block;
}
.skill-bar span.w70 {
    width: 70%;
}
.skill-bar span {
    width: 0;
    transition: width 1s ease;
    -webkit-transition: width 1s ease;
    background-color: #00edc2;
}
Run Code Online (Sandbox Code Playgroud)

它没有按预期工作.我需要在加载页面时进行转换.

但是当我检查元素并检查/取消选中width跨度时,我得到了效果.

如何对页面加载产生相同的影响?

在此输入图像描述

html javascript jquery css3 css-transitions

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

在express js中允许多个CORS域

如何以简化的方式在Express中允许多个域用于CORS.

我有

 cors: {
        origin: "www.one.com";
    }

    app.all('*', function(req, res, next) {
            res.header("Access-Control-Allow-Origin", cors.origin);
            res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
            next();
        });
Run Code Online (Sandbox Code Playgroud)

当只有一个域提到时,这个工作 origin

但是如果我想拥有origin一个域数组并且我想为原始数组中的所有域允许CORS,我会有这样的东西 -

cors: {
            origin: ["www.one.com","www.two.com","www.three.com"];
        }
Run Code Online (Sandbox Code Playgroud)

但问题是下面的代码不起作用 -

app.all('*', function(req, res, next) {
                res.header("Access-Control-Allow-Origin", cors.origin);
                res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
                next();
            });
Run Code Online (Sandbox Code Playgroud)

如何通过以下方式res.header获取一系列域名cors.origin

javascript node.js cors express

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

golang 在 http.ListenAndServe 之后执行函数

我开始通过创建一个简单的http服务器来学习golang

func main() {
    f, err := os.OpenFile("testlogfile", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
    if err != nil {
        fmt.Println("error opening file: %v", err)
    }
    defer f.Close()

    log.SetOutput(f)

    http.HandleFunc("/", defaultHandler)
    http.HandleFunc("/check", checkHandler)

    serverErr := http.ListenAndServe("127.0.0.1:8080", nil) // set listen port

    if serverErr != nil {
        log.Println("Error starting server")

    } else {
        fmt.Println("Started server on - 127.0.0.1:8080" )
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码将在 8080 上启动本地服务器,我可以通过浏览器访问路由。都很好!

但是,现在我想运行一个单独的 go 例程来监视文件 -

func initWatch() string{
    watcher, err := fsnotify.NewWatcher()
    if err != nil {
        fmt.Println(err)
    } …
Run Code Online (Sandbox Code Playgroud)

http go file-watcher

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

收听Angular组件上的click事件

如何在组件上侦听click事件并在组件上调用方法?

前 -

零件

import { Component } from '@angular/core';

@Component({
  selector: 'my-component',
  template: `
    <div>Hello my name is {{name}}. </div>
   `
})
export class MyComponent {
  name = "Aj"
}
Run Code Online (Sandbox Code Playgroud)

HTML -

<my-component></my-component> // user clicks here
Run Code Online (Sandbox Code Playgroud)

现在我该怎么听点击组件本身?

javascript angular

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