admin管理员组文章数量:1303411
I'm getting the following error from chrome console, when interpreting
<div [ngStyle]="{'width': '100%'; 'height': '100%'; 'background-size': 'cover'; 'background-repeat': 'no-repeat'; 'border-radius': '0px';}"></div>
Uncaught Error: Template parse errors: Parser Error: Missing expected } at column 17 in [{'width': '100%'; 'height': '100%'; 'background-size': 'cover'; 'background-repeat': 'no-repeat'; 'border-radius': '0px';}] in ng:///AppModule/HomeComponent.html@31:29 ("="width: 100%; height: 100%;">
What's supposed to cause the error?
I'm getting the following error from chrome console, when interpreting
<div [ngStyle]="{'width': '100%'; 'height': '100%'; 'background-size': 'cover'; 'background-repeat': 'no-repeat'; 'border-radius': '0px';}"></div>
Uncaught Error: Template parse errors: Parser Error: Missing expected } at column 17 in [{'width': '100%'; 'height': '100%'; 'background-size': 'cover'; 'background-repeat': 'no-repeat'; 'border-radius': '0px';}] in ng:///AppModule/HomeComponent.html@31:29 ("="width: 100%; height: 100%;">
What's supposed to cause the error?
Share edited Aug 29, 2017 at 16:59 Soviut 91.7k53 gold badges207 silver badges282 bronze badges asked Aug 29, 2017 at 16:57 user6039980user6039980 3,5068 gold badges36 silver badges59 bronze badges 2-
1
I guess
;
within the object literal should be instead,
– Günter Zöchbauer Commented Aug 29, 2017 at 16:59 - 1 @GünterZöchbauer This was obviously what I had to do. Thanks. – user6039980 Commented Aug 29, 2017 at 17:16
2 Answers
Reset to default 9Unlike the style
attribute which takes CSS styles, ngStyle
takes a javascript object (represented in a string). That's why you have to wrap 100%
in quotes '100%'
, as well as other attributes like background-size
because %
and -
characters are illegal in javascript attribute names/values.
CSS
blah {
attribute: value;
attribute-dash: value;
}
Object
{
attribute: value,
'attribute-dash': value
}
Because of this, you need to replace the ;
with ,
.
<div [ngStyle]="{'width': '100%', 'height': '100%', 'background-size': 'cover', 'background-repeat': 'no-repeat', 'border-radius': '0px'}"></div>
NOTE: ngStyle
is supposed to be used if you have dynamic values you're trying to set. It allows you to pass variables into the styles as well as toggle specific styles using booleans. If you're just trying to set inline styles, you should use the normal style
attribute.
In newer version you can also use unit.
The key is a style name, with an optional . suffix (such as 'top.px', 'font-style.em').
Like
[ngStyle]="{'width.px':200, 'height.px':200}"
本文标签: javascriptngStyle Error saying quotMissing expected quotStack Overflow
版权声明:本文标题:javascript - ngStyle: Error saying "Missing expected }" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741688713a2392595.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论