Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
conditional styling without 'else' in angularjs

I have a component that is being used by many pages:

<input 

  ng-style="{$ctrl.page0 ? 'border-color:blue' : ''}" 
  
  class="form-control" 
  type="text" 
  ng-change="$ctrl.dateChange()" 

/>

  <button ng-click="$ctrl.open()">Continue</button>

I want to use something like this:

ng-style="{$ctrl.page0 ? 'border-color:blue' : ''}"
ng-style="{$ctrl.page1 ? 'border-color:red' : ''}"
ng-style="{$ctrl.page2 ? 'border-color:yellow' : ''}"

But because of the "else", it won't work

What is the syntax to just use:

ng-style="{$ctrl.page0 ? 'border-color:blue'}"
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

According to the given details, Try below code.

    ng-style="{'border-color': $ctrl.page0 ? 'blue' : 
               ($ctrl.page1 ? 'red' : ($ctrl.page2 ? 'yellow' : '')) }"
about 4 years ago · Juan Pablo Isaza Report

0

You can write like this:

ng-style="$ctrl.page0 ? {border-color:'blue'} : {}"
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!