我的当前时间以毫秒为单位 - 1454521239279
如何将其转换为2016年2月3日和晚上11点10分?
虽然添加单个类以这种方式运行良好 -
[class.loading-state]="loading"
但是我如何添加多个类Ex如果loading是true添加类 -"loading-state" & "my-class"
我如何通过 [class] binding
如何在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)
[注意 - 我特别想添加一个新类,而不是修改现有的类]
叹!这是一个正常的用例,我还没有看到任何直接的解决方案!
假设我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) 例如:
我有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) 我想知道是否有×最大化或最小化的东西?
× 输出一个X,同样有什么内置可用于最大化和最小化?
我试图通过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跨度时,我得到了效果.
如何对页面加载产生相同的影响?

如何以简化的方式在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?
我开始通过创建一个简单的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) 如何在组件上侦听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)
现在我该怎么听点击组件本身?