Reputation: 416
Here is a part of my controller
:
function($scope, $http, $stateParams, $timeout, $q, $ionicPopup, $ionicActionSheet){
$http.get('topics/' + $stateParams.subTopicId + '.json').
success(function(data, status,header, config) {
$scope.questions = data;
});
}
Now here is a part of my view
:
<button ng-click="someFunc('{{questions[qNum].opt1}}')">
{{questions[0].opt1}}
</button>
In the above view {{questions[0].opt1}} works perfectly. But when passed as an arg to ng-click it becomes empty.
And again in my controller
:
function someFunc(aValue){
alert(aValue); // Empty
}
Why is the value of the variable aValue
empty.
On the other hand if, I directly declare $scope.questions
inside my controller like this:
$scope.question = [
{ ... }
];
Then someFunc
displays the value of the variable correctly. What is going on here?
What am I doing wrong?
Upvotes: 1
Views: 381
Reputation: 2368
Try this:
<button ng-click="someFunc(questions[qNum].opt1)">
Also, you are explicitly binding to element 0 when showing the property, but in your ng-click you are using a variable qNum, so be sure that is defined.
Upvotes: 2