Reputation: 523
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 = [];
$http.get('../Data.json')
.success(function (data, status, headers, config) {
// Alerts correct value
alert($scope.withCalc);
// 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 subjectSet
value, I have a ternary operator that checks the isCalc
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 ui-sref
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.
Upvotes: 0
Views: 1639
Reputation: 932
Check whether $scope.withCals
is not a String Object. You may need to convert it explicitly to Boolean.
Upvotes: 1