小编jps*_*sfs的帖子

如何在Angular2指令上访问Component?

我正在使用Angular 2进行一些测试,我有一个可以应用于我所有组件的指令(layout-item).

在该指令中,我希望能够读取组件上定义的一些元数据,但为此我需要访问组件的引用.

我尝试了以下方法,但我无法得到我需要的东西.有人有建议吗?

@Component({...})
@View({...})
@MyAnnotation({...})
export class MyComponentA {...}


// Somewhere in a template
<myComponentA layout-item="my config 1"></myComponentA>
<myComponentB layout-item="my config 2"></myComponentA>

// ----------------------

@ng.Directive({
    selector: "[layout-item]",
    properties: [
        "strOptions: layout-item"
    ],
    host: {

    }
})

export class LayoutItem {

    // What works
    constructor(@Optional() @Ancestor({self: true}) private component: MyComponent1) {

 // with the constructor defined like this, component is defined with myComponent1 instance.
Reflector.getMetadata("MyAnnotation", component.constructor); // > metadata is here!
    }

// What I needed
    constructor(@Optional() @Ancestor({self: true}) …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

VSTO工具:Office 2010至2013升级

我正在开发一个用于Excel的VSTO工具项目.我现在正在升级我的机器.我的"旧"笔记本电脑使用Office 2010和Visual Studio 2012运行Windows 7 x64.我的新机器具有带Office 2013和Visual Studio 2012的Windows 8 x64.

在VS2012上打开我的解决方案时,在新机器中,加载项目时出错:

无法创建项目,因为此计算机上未安装与此项目类型关联的应用程序.您必须安装与此项目类型关联的Microsoft Office应用程序.

我估计这是由于Office升级.除非真的有必要,否则我不想回到Office 2010.

你有什么建议吗?

最好的问候,jpsfs

c# vsto visual-studio-2012

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

setTimeout/Promise.resolve:Macrotask vs Microtask

我已经了解了Microtasks和Macrotasks的概念已有一段时间了,从我读过的所有内容中,我一直认为setTimeout会创建一个macrotask和Promise.resolve()(或process.nextTick在NodeJS上)来创建微任务.

(是的,我知道像Q和Bluebird这样的不同Promise库有不同的调度程序实现,但这里我指的是每个平台上的本机Promises)

考虑到这一点,我无法解释NodeJS上的以下事件序列(Chrome上的结果与NodeJS(v8 LTS和v10)不同,并且符合我对此主题的理解).

for (let i = 0; i < 2; i++) {
	setTimeout(() => {
		console.log("Timeout ", i);
		Promise.resolve().then(() => {
			console.log("Promise 1 ", i);
		}).then(() => {
			console.log("Promise 2 ", i);
		});
	})
}
Run Code Online (Sandbox Code Playgroud)

因此,我在Chrome上的结果(与我对Micro/Macro任务的理解以及Promise.resolve和setTimeout的行为方式一致)是:

Timeout  0
Promise 1  0
Promise 2  0
Timeout  1
Promise 1  1
Promise 2  1
Run Code Online (Sandbox Code Playgroud)

在NodeJS输出上执行的代码相同:

Timeout  0
Timeout  1
Promise 1  0
Promise 2  0
Promise 1  1
Promise 2  1
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种在Chrome上使用NodeJS获得相同结果的方法.我也用测试process.nextTick代替, …

javascript event-loop node.js

12
推荐指数
1
解决办法
746
查看次数

如何迭代Angular 2 ng内容项?

有谁知道如何迭代Angular 2 ng内容项?

我需要检查ng-content中存在的项目的属性值是什么.有谁知道如何获得它们?

最好的方案是在其中获取实际的组件实例,因为我可以在组件内部设置一些内部属性并直接访问它们会很棒!

一些示例代码:

// ====================== Container Component =======================

import * as ng from "angular2/angular2";

@ng.Component({
    selector: 'grid-layout',
    lifecycle: [ng.onInit]
})

@ng.View({
        templateUrl: `<div><ng-content></ng-content></div>`
})

export class GridLayout
{
    constructor(){

    }

    private onInit(): void {
         // ??? something like this.ngContent would be great :)
    }
}

// ====================== Caller Component =======================
import * as ng from "angular2/angular2";

@ng.Component({
    selector: 'my-page'
})

@ng.View({
    templateUrl: `
<grid-layout>
    <div data-att1="container 1">1</div>
    <div data-att2="container 2">2</div>
    <div>3</div>
</grid-layout>`,
    directives:[GridLayout]
})

export class MyPage …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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