dev*_*054 6 typescript angular
我有以下声明:
我object从以下某个地方收到了一个例子:
paginationConfig = {
'currentPage': 1,
'pageSizes': [5, 10, 15],
'perPage': 20
};
Run Code Online (Sandbox Code Playgroud)
我的课:
export class MyComponent implements OnInit {
currentPage: number;
pageSizes: number[];
perPage: number;
constructor() { }
ngOnInit(): void {
{ this.currentPage, this.perPage, this.pageSizes } = paginationConfig;
// It prints undefined for all those variables and I receive the error:
// TS1128: Declaration or statement expected.
// It works for local variables (as below), why not when I use **this**?
const { currentPage, perPage, pageSizes } = paginationConfig;
}
}
Run Code Online (Sandbox Code Playgroud)
那么我现在要做的是解构的object像例子这本书.
如果我使用局部变量,我可以使它工作,但在我的情况下,我真的希望这些是全局的.是不是可能/支持?
PS:我已经尝试将所有内容包装在括号中,它也不起作用.
Object.assign在班级内使用:
Object.assign(this, paginationConfig);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
650 次 |
| 最近记录: |