question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use calc() on fxFlex Expression

See original GitHub issue

Bug, 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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
CaerusKarucommented, May 15, 2018

It’s important to understand what this actually means:

  • [fxFlex]="value" means that fxFlex gets bound to the value of value in the component.
  • fxFlex="50" means that fxFlex gets bound to 50
  • [fxFlex]="value ? 50 : 60" means that fxFlex will be either 50 or 60 based on the value of value. 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 parse calc(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.

1reaction
spottedmahncommented, May 17, 2018

Thanks 🙏 @CaerusKaru

The solution is to wrap it in a string

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:

<div fxFlex="15" class="sec1" [fxFlex.xs]="myCondition ? 'calc(55% - 3em)' : 30">
  first-section
</div>

stackblitz.com example

Read more comments on GitHub >

github_iconTop 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 >
Fxlayout Using Calc - StackBlitz
fxFlex with calc() operations.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found