0

IN JS,
i have object as

var type = {};
type.showBox = false;

Using angular, i have to hide the input box.
It can be easily achieved by

$scope object ( "$scope.type.showBox = false;" )


But i want to use plain js in angular expression

<input type="text" ng-show="{{ type.showBox == true }}"/>
2
  • 2
    use ng-init nearest, but still angular expression, not real javascript. Commented Oct 7, 2015 at 12:18
  • ng-show will only show if the expression returns true... so the input box will be visible if your variable, type.showBox has a value of true. There is no need for an extra check Commented Oct 7, 2015 at 13:12

2 Answers 2

1

You cant, however what you can do, and in my opinion is going to be much cleaner, is to write a function in your controller

$scope.shouldShowBox=function(){
return $scope.type===true
}

Hope it helps

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

Comments

1

Remember that interpolation will display the output of the expression. So you have created an expression but not specified any output.

What you're looking for is:

ng-show="{{ type.showBox ? 'true' : 'false' }}"

However you don't need to interpolate (and it's probably better if you don't). All you need is:

ng-show="type.showBox"

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.