我有一个关于 Angular 性能的问题。引用公共属性和组件中定义的 getter 之间是否存在性能差异?
示例:
我有一个模板,它引用了isActivate在组件中定义的模板,如下所示:
<div *ngIf="isActivate">Do stuff...</div>
Run Code Online (Sandbox Code Playgroud)
在组件中:
export class TestComponent {
public isActivate: boolean;
Run Code Online (Sandbox Code Playgroud)
但它可以有一个 getter 来代替:
public get isActivate(): boolean {
return true;
}
Run Code Online (Sandbox Code Playgroud)
在性能方面,哪个更好,为什么?
具有如下所述的文件列表。
文件1:
{
id:1,
PostList:[
{
postname:"aaa",
lastdatetime:2017-07-13T17:10:25+05:30,
sname:"sas"
},
{
postname:"aaa1",
lastdatetime:2017-07-14T17:10:25+05:30,
sname:"sasadd"
},
{
postname:"aaa2",
lastdatetime:2017-07-10T17:10:25+05:30,
sname:"weq"
}
]
}
Run Code Online (Sandbox Code Playgroud)
文件2:
{
id:2,
PostList:[
{
postname:"aaa",
lastdatetime:2017-07-13T17:10:25+05:30,
sname:"sas"
},
{
postname:"aaa1",
lastdatetime:2017-07-14T17:10:25+05:30,
sname:"sasadd"
},
{
postname:"aaa2",
lastdatetime:2017-07-10T17:10:25+05:30,
sname:"weq"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我需要一个帖子名称列表,该列表等于“aaa”且 orderby lastdatetime。
我能够得到查询
select f.lastdatetime,f.postname
from c
join f in c.PostList
where f.postname='aaa'
Run Code Online (Sandbox Code Playgroud)
但我需要使用 orderby lastdatetime 获取列表。
当我尝试以下查询时,出现错误
不支持过度相关集合的排序
select f.lastdatetime,f.postname
from c
join f in c.PostList
where f.postname='aaa' ORDER BY f.lastdatetime ASC
Run Code Online (Sandbox Code Playgroud)
有人有想法可以通过吗?
我正在尝试实现自己的UrlSerializer类,这就是我所做的:
import { UrlSerializer,UrlTree } from '@angular/router';
export class CustomUrlSerializer implements UrlSerializer {
parse(url: string): UrlTree {
// Change plus signs to encoded spaces
url.replace("%20", '-');
// Use the default serializer that you can import to just do the
// default parsing now that you have fixed the url.
return super.parse(url)
}
serialize(tree: UrlTree): string {
// Use the default serializer to create a url and replace any spaces with + signs
return super.serialize(tree).replace("%20", '-');
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,我得到以下错误:
c:/xampp/htdocs/proj/src/app/custom-url-serializer.ts (11,12): …Run Code Online (Sandbox Code Playgroud)