user3391137
user3391137

Reputation: 441

how to pass a variable to the ternary condition in angularjs?

I tried this:

{{experience.current_work?"Present":{{experience.date_end | date:'MMM yyyy'}}}}

But this is wrong in ternary condition.How do I solve it?

Upvotes: 0

Views: 1957

Answers (2)

Rashedul.Rubel
Rashedul.Rubel

Reputation: 3584

You can do it like few ways:

Call the function below when you need to check the condition:

$scope.CheckCurrentWork = function() {
    if ($scope.experience.current_work) {
        //Do as you want "Present"
    } else {
        //Do as you want 
        experience.date_end | date: 'MMM yyyy'
    }
}

OR

{{experience.current_work ? "Present" : experience.date_end | date:'MMM yyyy'}}

OR

If you want to apply your condition in any directive

<div ng-click="experience.current_work ?'Present' :  experience.date_end | date:'MMM yyyy'">

Upvotes: -1

Phil
Phil

Reputation: 164776

You're already within an expression (ie {{...}}) so you don't need to start a new one

{{experience.current_work ? "Present" : experience.date_end | date:'MMM yyyy'}}

or maybe this if you're worried about order of evaluation

{{experience.current_work ? "Present" : (experience.date_end | date:'MMM yyyy')}}

Upvotes: 2

Related Questions