Controller defined in route is undefined when using Internet Explorer

2,026 views
Skip to first unread message

la...@sfeir.com

unread,
Aug 22, 2012, 10:45:03 AM8/22/12
to ang...@googlegroups.com
Hi guys

I encountered an issue using AngularJS with Internet Explorer 8.

I have followed http://docs.angularjs.org/guide/ie page.

I have defined some route :

app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when('/login', {
            templateUrl:'app/partials/login.html',
            controller:LoginCtrl})
        }
.....
}

My code work on Chrome.

However I got a javascript error telling me that LoginCtrl is undefined when using Internet Explorer


Where could this error comes from ?

Thanks you











        

Igor Minar

unread,
Aug 22, 2012, 10:54:03 AM8/22/12
to ang...@googlegroups.com
where is your LoginCtrl defined and when is this script loaded in relation to the rest of the app?


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

Thierry LAU

unread,
Aug 22, 2012, 10:57:49 AM8/22/12
to ang...@googlegroups.com
Thanks for your quick reply!

This is the order of the scripts loading in my index.html page

<script type="text/javascript" src="/app/lib/jquery/jquery.js"></script>
<script type="text/javascript" src="/app/lib/angularjs/angular.js"></script>
<script type="text/javascript" src="/app/lib/angularjs/angular-resource.js"></script>
<script type="text/javascript" src="/app/js/controllers.js"></script>
<script type="text/javascript" src="/app/js/app.js"></script>

The LoginCtrl is defined in my /app/js/controllers.js file.

Igor Minar

unread,
Aug 22, 2012, 11:02:06 AM8/22/12
to ang...@googlegroups.com
I assume that:

1/ there is no syntax error anywhere
2/ LoginCtrl is reachable from console after the app fails to bootstrap
3/ LoginCtrl is defined as a constructor function in the global namespace and not in a module

is all of this correct?

/i

Thierry LAU

unread,
Aug 22, 2012, 11:12:21 AM8/22/12
to ang...@googlegroups.com
1/ In fact, there is an another error encountered by IE.

Expected Identifier which pointed to the line  $http.delete of the following controller

function DogsCtrl($scope, $route, $http){

    $scope.deleteDog = function (dogId){
        $http.delete('/rest/dogs/' + dogId).
            success(function(data, status, headers, config) {
                $route.reload();
            }).
            error(function(data, status, headers, config) {
                $scope.$emit('error', status);
            });
    };
}


I don't know if their is a link between the two errors

2/ Yes It is reachable

3/ Correct. LoginCtrl is defined as followed :

function LoginCtrl($scope, $http,  $location){
    $scope.authenticate = function() {
        $http.get('/rest/login').
            success(function(data, status, headers, config) {
                $scope.$emit('event:userAuthenticated', data);
                if(data.userRole == 'Citoyen'){
                    $location.path("/citizen/dashboard");
                } else if (data.userRole == 'Fonctionnaire'){
                    $location.path("/functionnary/dashboard");
                }
            }).
            error(function(data, status, headers, config) {
                $scope.$emit('error', status);
            });
    }
}



2012/8/22 Igor Minar <ig...@angularjs.org>

Igor Minar

unread,
Aug 22, 2012, 12:57:21 PM8/22/12
to ang...@googlegroups.com
On Wed, Aug 22, 2012 at 8:12 AM, Thierry LAU <thie...@gmail.com> wrote:
1/ In fact, there is an another error encountered by IE.

Expected Identifier which pointed to the line  $http.delete of the following controller

function DogsCtrl($scope, $route, $http){

    $scope.deleteDog = function (dogId){
        $http.delete('/rest/dogs/' + dogId).

replace this with $http['delete'] and you should be good to go.

This has bit others already and I'm struggling with coming up with a good way to prevent that. If we rename $http.delete to $http.remove it will not match the HTTP method name, making the API look weird to anyone who doesn't know of this IE issue. On the other hand if we add an alias $http.delete_ or similar that will point to $http.delete only people that got bitten by this will use that api, at which point they might as well just use $http['delete'].

Thoughts?

/i

la...@sfeir.com

unread,
Aug 23, 2012, 4:02:52 AM8/23/12
to ang...@googlegroups.com
Hi  Igor,

I replaced $http.delete by $http['delete'] and It works now

Thank you for your help

Best Regards !

Mario J. Barchéin

unread,
Aug 23, 2012, 11:35:42 AM8/23/12
to ang...@googlegroups.com
Does uppercase property $http.DELETE work in IE8? Maybe that could be a reasonable workaround.
Reply all
Reply to author
Forward
0 new messages