在给定的属性指令示例(即添加外观/行为的指令)中,我们在主机元素上设置了一个相当简单的样式.例如
import {Directive, ElementRef } from 'angular2/core';
@Directive({
selector: '[myHighlight]'
})
export class HighlightDirective {
constructor(element) {
element.nativeElement.style.backgroundColor = 'yellow';
}
static get parameters(){
return [[ElementRef]];
}
Run Code Online (Sandbox Code Playgroud)
而不是设置样式,我可以使用样式吗?例如
@Directive({
selector: '[myHighlight]',
styles: [':host { background-color: yellow; }']
})
Run Code Online (Sandbox Code Playgroud)
这似乎对我不起作用?
我正在做一些稍微复杂的事情,这导致了相当数量的蒙特哥特代码,设置了很多样式,使用了AnimationBuilder等等.对我来说感觉就像把它分成CSS中的类和动画要好得多.
ViewEncapsulation =模拟/默认是否重要?
基本上在IE10的ap元素中,当"direction"是一行时,它的文本比它的父文件宽,会溢出,然后将任何其他兄弟姐妹推出容器.换行似乎在列模式下正常工作(您可以在Chrome中查看相同的jsfiddle并看到它按预期运行).
<div id="flex-one">
<p>Some extra long content (for the container) that correctly wraps!</p>
<aside>Content</aside>
</div>
<div id="flex-two">
<p>Some extra long content (for the container) that incorrectly wraps!</p>
<aside>Content</aside>
</div>
div {
width: 250px;
padding: 1em;
background: blue;
display: -webkit-flex;
display: -ms-flexbox;
margin-bottom: 1em;
}
#flex-one {
-webkit-flex-flow: column;
-ms-flex-direction: column;
}
#flex-two {
-webkit-flex-flow: row;
-ms-flex-direction: row;
}
p {
margin: 0;
padding: 0;
background: yellow;
}
aside {
background: red;
}
Run Code Online (Sandbox Code Playgroud)
有关如何纠正这种行为的任何想法,以便它不会溢出它的容器?(不提供固定的,因为它用于流体布局).
在浏览应用程序本身时使用动态生成的链接时,RouterLinkActive无效.
例如,在我的顶部导航中,我有这个;
<a [routerLink]=['user', currentUser.name] routerLinkActive='active'>{{currentUser.name}}</a>
Run Code Online (Sandbox Code Playgroud)
虽然硬编码版本可行.
<a [routerLink]=['user','bob']>View Bobs Account</a>
Run Code Online (Sandbox Code Playgroud)
这里有一个插件; https://plnkr.co/edit/BYKMucE3Y75uJSpV5VWx?p=preview
单击"John","Dynamic Router Link Name ="和"John"都应该处于活动状态.这有时适用于第一次点击,如果是这样,然后点击返回"主页",再次单击"约翰",您将看到只有硬编码链接被注册为活动,即使hrefs相同.
这是设计/不可能吗?还是我设置错误的东西?
我正在尝试同时处理许多任务,因为他们不需要每个人完成任务以进入下一个任务.我使用了同步过程并尝试将其变为异步.但是衡量业绩时,这两种方法采取完全相同的时间才能完成(30秒左右),我期望的异步要快...如果我1)得到了下面的正确2)了解异步是有益的(我怀疑这是问题).
public class ExpensiveTask {
private int _seed;
public ExpensiveTask(int seed){ _seed = seed; }
public Process() { //TODO various things }
}
public class Controller {
public static void main(string[] args){
var program = new Controller();
program.RunAsync(); // Runtime 36.9s
program.Run(); // Runtime 36.6s
}
void Run(){
Process(1);
Process(2);
Process(3);
}
async void RunAsync(){
var taskList = new List<Task>();
taskList.Add(ProcessAsync(1));
taskList.Add(ProcessAsync(2));
taskList.Add(ProcessAsync(3));
await Task.WhenAll(taskList);
}
async Task ProcessAsync(int seed){
var task = new ExpensiveTask(seed);
task.Process();
}
void Process(int seed){ …Run Code Online (Sandbox Code Playgroud)