How to call a function in my controller that is used as a scope

I call the fetchData function with the click of a button and completely retrieve the full data set, I need to pass the form view, this is the value of the element,

I want to reuse this function, and when I call this function and pass this element value, it does not call the function at all, how can I reuse this function.

$scope.fetchData = function(item) {
        $scope.selectedData = item;
        var entry = ServiceName.ServiceItem.query({
            item: item,
        }, function() {
            $scope.item_array = entry;
        });
    }
 if(some_condition)
 {//$stateParams.item_valis used to fetch the data
 $scope.item_array = $scope.fetchData($stateParams.item_val);
 /* this call works perfectly
 var entry = ServiceName.ServiceItem.query({
            item: $stateParams.item_val,
        }, function() {
            $scope.item_array = entry;
        }); */

 }
+4
source share
1 answer
$scope.fetchData = function fetchData (item) {
            $scope.selectedData = item;
            var entry = ServiceName.ServiceItem.query({
                item: item,
            }, function() {
                $scope.item_array = entry;
            });
    }

It returns undefined (by default) because you are not returning anything and assigning (provided):

$scope.item_array = $scope.fetchData($stateParams.item_val);
0
source

Source: https://habr.com/ru/post/1620302/


All Articles