Search code examples
jqueryangularjsternary

Ternary Operator Angular JS


I have $scope.lineData[0].line in my controller. I want to check $scope.lineData[0] != undefined , If so then $scope.lineData[0].line else just "0" value to add. How can do this with angular JS ?

Can anyone help me to do this? Thanks in advance..


Solution

  • In Template we would do it something like

    {{ lineData[0] ? lineData[0].line : "0" }}
    

    In Controller, we'll be doing

    var some_value = $scope.lineData[0] ? $scope.lineData[0].line : "0";