0

My HAML file:

%pipes-autocomplete{:model =>"filter.value",:option => "validate_option(filter)" ? "dependant(filter)" : "filter.option"}

My Coffee Script:

  $scope.validate_option =(filter)->
     console.log "called validate_option"
     if filter.hasOwnProperty('option') && filter.option.indexOf('dependant') > -1
       return true
     else
      return false
  $scope.dependant =(cal)->
    return "choosed"

In the ternary operator I'm trying to call the validate_option function defined in my angular controller.But the function is not getting called.Can someone help me with this problem.

2
  • As you put it now the ternary operator will consider the string to be true (just because it is not an empty one). Try with "validate_option(filter) ? dependant(filter) : filter.option" (all in one string), so that you defer the execution of the ternary operator to when the string is evaluated. Commented Jul 14, 2016 at 12:30
  • @trincot Thank you so much. It works fine.I am a newbie to angular.And my doubts got cleared with your explanation. Commented Jul 14, 2016 at 13:18

1 Answer 1

2

As you put it in the question, the ternary operator will consider the string "validate_option(filter)" to be true (just because it is not an empty one).

Instead put the ternary operator inside the string:

"validate_option(filter) ? dependant(filter) : filter.option"

That way you defer the execution of the ternary operator to when the string is actually evaluated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.