2

I have an element inside my html where i have to check type of an variable, whether its boolean or not.

<button process-indicator="{{typeof(button.processIndicator) === 'boolean' ? 'modalProcess' : 'modalClose'}}"/>

here process indicator is my directive. But in my case its always setting value to 'modalClose'.

What I am doing wrong here.

1
  • 1
    Try to do the logic in a function and return the respective indicator value. Something like this. Commented Feb 5, 2015 at 5:17

1 Answer 1

2

Since typeof() is a JavaScript function, and {{ }} are for Angular expression execution, so we are not able to execute JavaScript code or function inside Angular expressions.

To make this happen we need to assign the result value to some $scope variable so that it can be utilised inside our HTML using Angular expressions.

We have to do something similar to explain above by @anpsmn in his fiddle. Which is :

HTML :

<div ng-app="app" ng-controller="testCtrl">
<p process-indicator="{{checkType()}}">Value: {{checkType()}}</p>    

Controller :

angular.module("app",[])
.controller("testCtrl",['$scope', function($scope){

$scope.processIndicator = false;

$scope.checkType = function() {
    return typeof($scope.processIndicator)==='boolean'? 'modalProcess' : 'modalClose';
}; 

}])
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.