Rigoberto Molina Rigoberto Molina - 24 days ago 4x
AngularJS Question

AngularJS boolean value always returns true in scope

So I have a state which takes two specific parameters (subjectID & isCalc):

.state('tabsController.formulaPicker', {
url: '/my/:subjectID?withCalc',
views: {
'tab1': {
templateUrl: 'templates/formulaPicker.html',
controller: 'formulaPickerCtrl'

& In my controller I have:

.controller('formulaPickerCtrl', function ($scope, $stateParams, $http) {
$scope.subjectID = $stateParams.subjectID;
$scope.subjectName = '';
$scope.withCalc = $stateParams.withCalc;
$scope.formulas = [];

.success(function (data, status, headers, config) {
// Alerts correct value
// Always returns true
$scope.subjectSet = ($scope.withCalc) ? data.subjects : data.subjects_no_calc;
$scope.subjectName = $scope.subjectSet[$scope.subjectID].name;
$scope.formulas = $scope.subjectSet[$scope.subjectID].formulas;
.error(function (data, status, headers, config) {
.then(function (result) {

But in the line where I declare the scope's
value, I have a ternary operator that checks the
bool value, it returns a specific set of data from the json file I'm requesting. Every time I load the controller it alerts the isCalc value, which I want & is correct. But the ternary expression always returns true, even though it alerted false. This causes me to return the wrong set of values.

I two
properties from the first controller:

ui-sref="tabsController.formulaPicker({subjectID: $index, withCalc: true})"

for the first section

"tabsController.formulaPicker({subjectID: $index, withCalc: false})"

for the second section.

Remember it alerts the correct value but the ternary expression always returns true no matter what.

Thank you in advance.


Check whether $scope.withCals is not a String Object. You may need to convert it explicitly to Boolean.