0

I am using AngularJS with ASP.NET MVC to create an application which uses Angular controllers for the front end. When I run the application on my development system, it works fine. When I deploy it on my local IIS, it works fine. BUT, when I deploy it the to production server IIS, the angular controller does not load and it requires refreshing the page to get it to work.

I have looked at the similar questions, for instance: Angular app only loads on page refresh

I also do not have any other extensions or plugins installed to affect the behavior as suggested in other similar questions.

I have moved all the JS in bundles, but that also to no avail. The order of the JS also seems to be correct because it works perfectly well on the development system, and local IIS.

I have no other idea on how to proceed with this issue.

Here's the screenshot for the error in the console:

Controller not found.

And here's the code:

For HomeController,

app.controller('homeController', function ($scope, $uibModal, HomeService, RequestService) {
    $scope.refreshOriginatorForms = function (searchCriteria) {
        HomeService.getOriginatorRequestForms(searchCriteria).then(function (response) {
           ....
        });
    }
    var originatorSearchCriteria = {
        Pager: {
            ItemsPerPage: 10,
            CurrentPage: 1
        }
    };
    $scope.OriginatorFormsSearchCriteria = originatorSearchCriteria;
    $scope.initialize = function () {
        $scope.refreshOriginatorForms($scope.OriginatorFormsSearchCriteria);
    };
}

The $scope.initialize method is called in the view with ng-init="initialize()"

6
  • can you share screenshots from your browser console, first time your app launches and is not working correctly ? Commented Jul 25, 2017 at 7:33
  • @Sameer: Can you share your app and controller code? Commented Jul 25, 2017 at 7:38
  • @ArashKhajelou that's correct, it does not work for the first time, and that is happening for every page in the application using angular. However, on refreshing, that particular page works fine. Commented Jul 25, 2017 at 7:39
  • @VindhyachalKumar the code is working fine on my local development system. I, however, cannot share the code. Commented Jul 25, 2017 at 7:44
  • i think you have some errors with the synchronous request of angular, some thing like you are going to get the user data, but you use it before fetching, and it's actually the reason that it works on local servers correctly, on local servers responses of server are faster and controller faces no error, if you share your code i can help you more and exact Commented Jul 25, 2017 at 7:47

2 Answers 2

1

I have moved all the JS in bundles

If you are minimizing angular controllers then you should write our controller like this to that minimizers does not rename important angular keywords like $scope

app.controller('homeController',['$scope','$uibModal','HomeService','RequestService', function ($scope, $uibModal, HomeService, RequestService) {
$scope.refreshOriginatorForms = function (searchCriteria) {
    HomeService.getOriginatorRequestForms(searchCriteria).then(function (response) {
       ....
    });
}
var originatorSearchCriteria = {
    Pager: {
        ItemsPerPage: 10,
        CurrentPage: 1
    }
};
$scope.OriginatorFormsSearchCriteria = originatorSearchCriteria;
$scope.initialize = function () {
    $scope.refreshOriginatorForms($scope.OriginatorFormsSearchCriteria);
};
}])
Sign up to request clarification or add additional context in comments.

1 Comment

I actually tried all that... but nothing worked, Finally, I was discussing the problem with the team, domain administrator, he suggested enabling the CDN on the domain. Which eventually made everything work? For now I have no idea what all that was about, but its working now...
0

We finally got it solved. Our network engineer suggested enabling the CDN on the DNS, and it worked. All this time, looking at the code, and the issue was something else.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.