1

I have this Angular Controller:

(function () {
    "use strict";
    angular.module('appContacts')
        .controller('organizationsController', function organizationsController(dataService, $stateParams) {

            var vm = this;
            vm.visible = false;
            var id = $stateParams.Id;
            activate();

            function activate() {
                dataService.GetOrganizationById(id).then(function (result) {
                    vm.organization = result.data;
            }, function () {
                vm.errorMessage = "Failed to load" + Error;
            });
        }
    });
})();

Here is my dataService file:

(function () {

    angular.module('appContacts')
        .factory('dataService', ['$http', dataService]);

    function dataService($http) {
        return {
            getAllOrganizations: getAllOrganizations,
            GetOrganizationById: GetOrganizationById,
        };

        function getAllOrganizations() {
            return $http({
                method: 'GET',
                url: 'api/organizations'
            });
        }

        function GetOrganizationById(id) {
            return $http({
                method: 'GET',
                url: '/api/organizations/{id}'
            });
        }
})();

This dataService.js call the GetOrganizationById method in the repository like this:

...
    public Organization GetOrganizationById(Guid Id)
    {
        return _context.Organizations
            .Include(o => o.Contacts)
            .ThenInclude(c => c.Phone.main == true)
            .Where(o => o.Id == Id)
            .FirstOrDefault();
    }
...

The repository gets the info successfully, send back to dataService.js and reach this line in the organizationsController.js. I could see in the Chrome debugger:

dataService.GetOrganizationById(id).then(function (result) 

However in the next line, the data is lost and the system returns a 204 Error Code: No Data.

vm.organization = result.data; 

Any idea why the Controller would not accept the data that is sent in the variable "result"?

I am working in Visual Studio 2015 EF and C# the back end. But the problem is just in the front-end because I get info and I see it also with Postman

Rafael Munoz
  • 636
  • 1
  • 7
  • 27

0 Answers0