Can't use calc() on fxFlex Expression
See original GitHub issueBug, feature request, or proposal:
Bug (or Feature request if it is not supposed to work this way)
What is the expected behavior?
That I can use calc()
in a fxFlex
expression: [fxFlex.xs]="myCondition ? calc(55% - 3em) : 30"
What is the current behavior?
<div fxFlex="15" class="sec1" [fxFlex.xs]="myCondition ? calc(55% - 3em) : 30">
first-section
</div>
Template parse errors: Parser Error: Unexpected token Lexer Error: Invalid exponent at column 26 in expression [myCondition ? calc(55% - 3em) : 30]
What are the steps to reproduce?
stackblitz.com/edit/angular-flex-layout-expression-flex-calc
What is the use-case or motivation for changing an existing behavior?
Dynamically control fxFlex
when using fxLayoutGap
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Use of calc() inside fxFlex not working on edge - Stack Overflow
I've read that there's no way Edge works with calc() inside of a fxFlex. How can I make it work? Is there any...
Read more >can't use temporary expression in write context - You.com | The ...
I'm getting the following error (Can't use temporary expression in write context). The error is coming from this line of code:.
Read more >angular/flex-layout - UNPKG
n *\n * Use of this source code is governed by an MIT-style license that can be\n ... Calc expressions require whitespace before...
Read more >Category: HTML, CSS, and Angular Material
I have been using the Angular Material mat-menu for playlist selection. ... The user pretty much cannot do anything until picking a playlist....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s important to understand what this actually means:
[fxFlex]="value"
means that fxFlex gets bound to the value ofvalue
in the component.fxFlex="50"
means that fxFlex gets bound to 50[fxFlex]="value ? 50 : 60"
means thatfxFlex
will be either 50 or 60 based on the value ofvalue
. Note that 50 or 60 could be bound to other values, as you have in your StackBlitz example. The important thing is that the template parser interprets 50 or 60 as integer values[fxFlex]="value ? calc(50% - 1em) : 50"
. What’s happening here is the template parser is trying to parsecalc(50% - 1em)
as a variable reference.The solution is to wrap it in a string, so that the directive knows that it’s just a string reference. Alternatively, you can bind this to a variable in the component.
Thanks 🙏 @CaerusKaru
Just to clarify “it”. You meant the calc function by it. I wasn’t sure what it was… took me a while to figure that out. I first tried the whole expression and that of course didn’t work.
I’m pretty sure you meant:
[fxFlex]="value ? 'calc(50% - 1em)' : 50"
will work.To complete the circuit, if you will, I am able to do this:
stackblitz.com example