0

My Angular coding is rusty as I haven't done it in a while but what I am trying to do is take a list of values returned from a list controller and inject them into my Response post to a search controller that will use this list to search a repository.

This is what I have tried so far--

1 - initialize the list array with Guid:[] in the $scope.data{} initializer

//Initailize 
$scope.data = {
    selection: null,
    start: '',
    end: '',
    minDate: new Date(2017, 01, 01),
    defaultStartDate: moment({ year: currentDate.getFullYear(), month: currentDate.getMonth(), day: currentDate.getDate() }),
    defaultEndDate: moment({ year: currentDate.getFullYear(), month: currentDate.getMonth(), day: currentDate.getDate() + 1 }),
    format: 'YYYY-MM-DD HH:mm:ss.SSS',
    elasticUrl: '',
    dnsHost: '',
    messageTypes: [],
    scrollId: '',
    TID: '',
    Guids: []
};

2 - return the list that I am interested in from a search controller with $scope.Guids = data.Guids

var search = function () {
    NProgress.start();
    var ospLogsSearchParam = {
        StartDate: $scope.data.start,
        EndDate: $scope.data.end,
        ElasticUrl: $scope.data.elasticUrl,
        MessageTypes: $scope.data.messageTypes,
        DnsHost: $scope.data.dnsHost,
        TID: $scope.data.TID,
    };
    var queryString = $.param(ospLogsSearchParam);
    $http.get("/api/search?" + queryString).success(function (data) {
        $scope.isLoading = false;

        $scope.total = data.Total;
        $scope.took = "";
        $scope.tookMins = "";
        $scope.successCount = "";
        $scope.errorCount = "";
        $scope.tps = "";
        $scope.Guids = data.Guids; (data list)
    }).finally(function () {
        NProgress.done();
    });
}

3 - inject this value (Guids: $scope.data.Guids) into the Guids field in the SearchParameter object that I am sending a second search controller.

function invokeParse() {
    var ospLogsSearchParam = {
        StartDate: $scope.data.start,
        EndDate: $scope.data.end,
        ElasticUrl: $scope.data.elasticUrl,
        MessageTypes: $scope.data.messageTypes,
        DnsHost: $scope.data.dnsHost,
        TID: $scope.data.TID,
        Guids: $scope.data.Guids (data trying to send to back end controller)
    };
    var parse = {
        Logs: $scope.filteredItems,
        DNSName: !$scope.data.dnsHost ? 'none' : $scope.data.dnsHost,
        OspLogsSearchParams: ospLogsSearchParam
}

Expected result is that the back end search controller will perform a search using each value in the list as the where filter.

Actual result is that the guid list is not being populated with that values from the search request.

B. Youngman
  • 123
  • 1
  • 12
  • The `.success` method has been [removed from the AngularJS framework.](https://stackoverflow.com/questions/35329384/why-are-angularjs-http-success-error-methods-deprecated-removed-from-v1-6/35331339#35331339) – georgeawg Jul 08 '19 at 17:47
  • This is a legacy project that I'm working on and everything else is working fine meaning that the master search is working as is it is when I go to populate the list of guids that I'm having problems. – B. Youngman Jul 08 '19 at 19:24
  • Your use of the term "controller" is a bit confusing. How many AngularJS controllers are involved in this? I get the impression that "list controller" is your AngularJS controller and "search controller" is a remote service. – Jack A. Jul 08 '19 at 19:52
  • Just figured it out - I wasn't populating the correct Guid array object I needed to be populating $scope.data.Guids and not data.Guids. Once I did that it started functioning correctly . To clarify the last comment I should have been clearer in my usage of the term 'controller' - it was a backend C# Controller and not an angular controller. – B. Youngman Jul 08 '19 at 20:09

0 Answers0