Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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中格式化硬编码json对象_Angular_Typescript - Fatal编程技术网

Angular 使用锯齿数组在TypeScript中格式化硬编码json对象

Angular 使用锯齿数组在TypeScript中格式化硬编码json对象,angular,typescript,Angular,Typescript,我可能在这里很笨,但我不明白为什么 productSpecificStyling: any; this.productSpecificStyling = { headerDividerStyle: { height: "5px"}, buttonNext: { color: "purple"}, buttonPrevious: { color: "yellow" } }; 很好,但是

我可能在这里很笨,但我不明白为什么

  productSpecificStyling: any;

  this.productSpecificStyling = {
      headerDividerStyle: { height: "5px"},
      buttonNext: { color: "purple"},
      buttonPrevious: { color: "yellow" }
  };
很好,但是

  productSpecificStyling: any;

  this.productSpecificStyling = {
      headerDividerStyle: { height: "5px",width:"100px"},
      buttonNext: { color: "purple"},
      buttonPrevious: { color: "yellow" }
  };
引发错误,抱怨存在:应为

编辑:对不起,伙计们,当我粘贴这个的时候,我一直在做实验,我想这和背景色有关

  productSpecificStyling: any;

  this.productSpecificStyling = {
      headerDividerStyle: { height: "5px",background-color:"red"},
      buttonNext: { color: "purple"},
      buttonPrevious: { color: "yellow" }
  };

ProductSpecific样式:任何

this.productSpecificStyleing={headerDividerStyle:[{高度:“5px”,宽度:“100px”}],按钮下一步:{颜色:“紫色”},按钮前一步:{颜色:“黄色”}


将数组添加到headerDividerStyle。。。应该很好

马洛里奇指出了方向。hypen在JSON属性中无效,但我必须创建它!。把它封闭在[“”]中使它起作用。e、 g

 this.productSpecificStyling = {
      headerDividerStyle: { height: "5px",["background-color"]:"red"},
      buttonNext: { color: "purple"},
      buttonPrevious: { color: "yellow" }
  };

我在我的IDE中也尝试过同样的方法,但没有出现任何这样的错误。你们有更完整的样品吗?另外,这是导致问题的确切代码吗?(也就是说,你复制粘贴了吗)你是正确的,我创建了这个具体的例子来说明,但它并不完全是错误-对不起,伙计们。错误是当“宽度”改为“背景色”——我之前一直在试验——我想这与宣传有关。我不确定我是否理解你的逻辑。不需要数组,它会更改headerDividerStyle的类型。仅当您希望有多个项目时才使用数组。实际上,您不需要“背景色”周围的方括号-引号应该足够了。