Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在Typescript中解构赋值_Angular_Typescript - Fatal编程技术网

Angular 在Typescript中解构赋值

Angular 在Typescript中解构赋值,angular,typescript,Angular,Typescript,is代码通过解构对象并分配变量,工作正常 const { allowNegative, decimal, precision, prefix, suffix, thousands } = this.options; 但是当我尝试使用下面这样的操作符时,它会抛出一个错误: { this.tabConfig, this.searchUiConfig, this.gridUiConfig } = CONFIG; 其中CONFIG是一个JSON。赋值运算符(=)上的[ts]声明或语句应为时出错 有没

is代码通过解构对象并分配变量,工作正常

const { allowNegative, decimal, precision, prefix, suffix, thousands } = this.options;
但是当我尝试使用下面这样的
操作符时,它会抛出一个错误:

{ this.tabConfig, this.searchUiConfig, this.gridUiConfig } = CONFIG;
其中CONFIG是一个JSON。赋值运算符(=)上的[ts]声明或语句应为时出错

有没有比这更好的方法:

 this.tabConfig = CONFIG.tabConfig;
 this.searchUiConfig = CONFIG.searchUiConfig;
 this.gridUiConfig = CONFIG.gridUiConfig;

可以使用以下语法执行此操作:

({ prop: this.prop } = obj);
这里我用的是一个

在左侧,您将说明要从对象获取的属性,在右侧,您将说明存储值的位置。因此,在这种情况下,将使用
foo
value创建一个名为
whereToStoreValue
的新变量

var obj = { propIwantFromObj: 'foo' };
var whereToStoreValue = obj.propIwantFromObj;
可用于存储
(或其他对象)上的值,但由于
,您需要将其环绕在括号中。出于某种原因,此黑客允许您使用

如果不使用括号,将出现语法错误(在纯JS中也不起作用)

例如:

const-CONFIG={
tabConfig:1,
searchUiConfig:2,
gridUiConfig:3,
};
福班{
bar(){
({tabConfig:this.tabConfig,searchUiConfig:this.searchUiConfig,gridUiConfig:this.gridUiConfig}=CONFIG);
}
}
const foo=新foo();
foo.bar();
log(foo.tabConfig);
console.log(foo.searchUiConfig);

log(foo.gridUiConfig)很有用…你能简单地解释一下发生了什么吗?当然,希望能有帮助。这很好,我喜欢
({prop:This.prop}=obj)。非常感谢你。
var obj = { propIwantFromObj: 'foo' };
var whereToStoreValue = obj.propIwantFromObj;