Is there a way to avoid using large IF statements in my controller when working with fields/models that have similar logic but different scope variable names? I'm looking for a solution to dynamically append numbers to the scope variable names in Angular, instead of having $scope.search1 and $scope.search2. Is this feasible?
For instance, can I achieve something like $scope.search + id rather than hardcoding each scope variable name? How would I go about implementing this in Angular?
In my controller:
$scope.getresults= function() {
if ($scope.search1) {
$http.jsonp('http://api.com/', {
params: {
query: $scope.search1
}
if ($scope.search2) {
$http.jsonp('http://api.com/', {
params: {
query: $scope.search2
}}}
I'd prefer to do something like:
$scope.getresults= function(param) {
$http.jsonp('http://api.com/', {
params: {
query: $scope.search + param
}}
Unfortunately, this approach does not work as intended. Any assistance on how to address this issue would be greatly appreciated.