假设我有一个具有固定输入参数类型的组件,
@Component({
selector: 'fixed',
template: '<div>{{value}}</div>'
})
export class FixedComponent {
@Input() value: string;
}
Run Code Online (Sandbox Code Playgroud)
我如何将该参数类型设为通用,即
@Component({
selector: 'generic',
template: '<div>{{value}}</div>'
})
export class GenericComponent<T> {
@Input() value: T;
}
Run Code Online (Sandbox Code Playgroud)
也就是说,如何在父组件的模板中传递类型?
<generic ...></generic>
Run Code Online (Sandbox Code Playgroud) 如何使用 检测scrollHeightDOM 元素的更改时间MutationObserver?它不是属性,也不是数据。
背景:我需要检测滚动条何时出现在我的内容元素上,overflow-y其设置为自动。我认为滚动条出现的那一刻,值就会scrollHeight从 0 跳到 500,所以我的想法是设置 aMutationObserver来检测此属性的变化。
到目前为止我所得到的:
HTML
<div class="body" #body>
Run Code Online (Sandbox Code Playgroud)
CSS
.body {
overflow-y: auto;
}
Run Code Online (Sandbox Code Playgroud)
打字稿
export class MyWatchedContent implements AfterViewInit, OnDestroy {
@ViewChild('body', { read: ElementRef })
private body: ElementRef;
private observer: MutationObserver;
public ngAfterViewInit() {
this.observer = new MutationObserver(this.observerChanges);
this.observer.observe(this.body.nativeElement, {
attributes: true,
});
}
public ngOnDestroy() {
this.observer.disconnect();
}
private observerChanges(records: MutationRecord[], observer: MutationObserver) {
console.log('##### MUTATION');
records.forEach((_record) => {
console.log(_record);
});
} …Run Code Online (Sandbox Code Playgroud) 我希望能够在Visual Studio Code中调试单元测试,但到目前为止它已经是一个混合包.
我的设置:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug tests",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
}
]
}
Run Code Online (Sandbox Code Playgroud)
karma.config.js
customLaunchers: {
Chrome_with_debugging: {
base: 'Chrome',
flags: ['--remote-debugging-port=9222']
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎在某种程度上起作用,如果我启动VS Code调试器它似乎附加(底栏变为橙色).如果我做出改变,Karma也会启动和调试器 - 但它总是暂停zone.js(顺便说一下这是一个Angular项目)而不会干扰我:
如果我点击"继续"它实际上击中了我的断点
我可以检查一些变量,但不是全部,
例如,我看不到actual传递给Jasmine expect方法的值.
所以a)为什么调试器总是在内部暂停zone.js- 测试的代码来自Redux reducer并在任何Angular上下文之外调用,以及b)我无法检查局部变量(这是一个showstopper)马上)?
其实,我的一个同事问过我这个问题,我一直没能想出答案。开始。
给定一个有 2 个外键的实体,比如说
public class MyTable
{
public int Key1 { get; set; }
public int Key2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和 2 个列表
public ICollection List1 => new List<int> { 1, 2, 3 };
public ICollection List2 => new List<int> { 4, 5, 6 };
Run Code Online (Sandbox Code Playgroud)
他需要查询 Key1 与 List1 中的值匹配且 Key2 与 List2 中的值匹配的所有记录,例如
Key1 == 1 && Key2 == 4
Run Code Online (Sandbox Code Playgroud)
也就是说,他想检查 List1 和 List2 中的任何给定元组,(1, 4), (2, 5) 和 (3, 6)。
EF 中是否有一种直接的方法可以做到这一点?
我已经开始学习DDD的原理了,我现在正试图掌握有界上下文的概念.特别是,你如何决定它有多大(或小)?是的,我知道,尽可能小,必要的大(根据Vaughn Vernon).
假设我要为博客建模.然后我可以说有3个有界的背景:1)Front Page(以最新的文章为特色,没有显示评论)2)讨论(包括评论的单篇文章)3)Article Composer(我撰写文章的地方).
然而,这感觉不对(无处不在的语言对所有人来说都是一样的),似乎我是从前端角度来看,我仍然在考虑视图模型或其他东西.
有谁能请我指出正确的方向?
我在子组件中设置辅助路由时遇到问题,由于某种原因,只有那些辅助路由才能从根组件开始工作.
这是我的路由器设置
export const routes: RouterConfig = [
{ path: 'test1', component: Test1Component },
{ path: 'test2', component: Test2Component, outlet: 'aux'},
{ path: 'shell', component: ShellComponent, children: [
{ path: 'department/:id', component: DepartmentDetailComponent },
{ path: 'test3', component: Test3Component, outlet: 'aux2' } ] }
];
Run Code Online (Sandbox Code Playgroud)
如果我导航到
http://localhost:3000/shell/department/1(aux:test2)
Run Code Online (Sandbox Code Playgroud)
然后输出是预期的,也就是说,Test2Component在内部AppComponent,以及ShellComponent和DepartmentDetailComponent:
主要插座显示为蓝色,辅助插座为红色.
但是,如果我尝试导航到
http://localhost:3000/shell/department/1(aux2:test3)
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:
platform-browser.umd.js:1900 EXCEPTION:错误:未捕获(在承诺中):错误:无法匹配任何路由:'test3'
router-outlets 如下面所述:
app.component.ts(aux:test2)
<div class="app">
<h1>App</h1>
<div class="primary-outlet">
<router-outlet></router-outlet>
</div>
<div class="aux-outlet">
<router-outlet name="aux"></router-outlet>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
shell.component.ts(aux2:test3)
<div …Run Code Online (Sandbox Code Playgroud) 假设我有以下设置:
employee -------+ employee.module.ts
| employee.routing.ts
+ employee.component.ts
|
sales ----------+ sales.module.ts
| sales.routing.ts
+ sales.component.ts
app.module.ts
app.routing.ts
app.component.ts
Run Code Online (Sandbox Code Playgroud)
而且我希望我的路线看起来像
employee/14/sales
Run Code Online (Sandbox Code Playgroud)
所以我继续定义这些路由声明:
app.routing.ts
...
import { AppComponent } from './app.component';
const appRoutes: Routes = [
{ path: '', component: AppComponent }
];
export const appRoutingProviders: any[] = [];
export const routing = RouterModule.forRoot(appRoutes, { useHash: true });
Run Code Online (Sandbox Code Playgroud)
employee.routing.ts
...
import { EmployeeComponent } from './employee.component';
export const employeeRoutes: Routes = [
{ path: 'employee/:id', component: EmployeeComponent }
];
export const …Run Code Online (Sandbox Code Playgroud) 假设我想从商店中检索一组记录,使用*ngFor例如,在列表中显示它们
<ul>
<li *ngFor="let record in records | async">
...
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
现在用户点击"新建..."按钮,另一条记录被添加到商店和
recordAdded: EventEmitter<string>;
Run Code Online (Sandbox Code Playgroud)
火来告诉我这个位置.因此,我从商店获得了新记录 - 仅记录 - 并且...哎呀,我如何让我*ngFor显示这个额外的记录?
好的,所以我可以将所有记录保存在数组中,例如
_records: Record[];
Run Code Online (Sandbox Code Playgroud)
并通过订阅填补这个阵列Observable<Record[]>等
this.recordService.getAll().subscribe(r => this._records = r);
Run Code Online (Sandbox Code Playgroud)
但是这个数组需要是一个Observable自己,以便在有新记录时通知消费者.所以
observableRecords = Observable.create(obs => {
this.recordService.getAll().subscribe(rec => {
this._records = rec;
obs.next(rec);
// Got the array published, now waiting for events
this.recordAdded.subscribe(rec => {
this._records.push(rec);
obs.next(this._records);
});
});
});
Run Code Online (Sandbox Code Playgroud)
呃...这不仅令人难以忍受,还有大量的开销,因为每次添加新记录时整个阵列都会重新发布 - 最有可能的是 - Angular 2将从头开始重新构建整个列表动不动.
由于这是一个常见的场景,我想有必要有一个更好的方法来做到这一点.
看来,UWP应用程序缺少静态方法Attribute.IsDefined,我可以导航到Attribute类的元数据,并且该方法在那里,但是项目不会编译,说明“ Attribute”不包含针对'IsDefined'-很奇怪(事实上,根据IntelliSense,该类型上根本没有静态方法)。
我要查询具有特定属性的类型,例如
var types = this.GetType().GetTypeInfo().Assembly.GetTypes()
.Where(t => Attribute.IsDefined(t, typeof (MyAttribute)));
Run Code Online (Sandbox Code Playgroud)
并且想知道是否有解决方法。
我试图在组件的参数更改时触发动画,但只能在组件第一次路由到时执行动画。使用不同参数对该组件的所有后续导航都不会触发动画。
例如,请参阅此 plunker。
从导航时
/home
Run Code Online (Sandbox Code Playgroud)
到
/home/animated/1
Run Code Online (Sandbox Code Playgroud)
动画正在执行。如果只有 ID 更改,例如
/home/animated/2
Run Code Online (Sandbox Code Playgroud)
什么也没有发生。我错过了什么或者这是预期的行为?