Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I decided after much debate, to split my webpage into two parts, one for ie7 and another for ie8+. I have many

<!-- if lte ie7---> 

scattered around, and I just want to separate the html as much as possible. Sure it's heavier maintenance, but whatev.

So as I moved my html content from the main.html to submain.html, I noticed one of my custom directives wasn't working.

Note: All my javascript gets loaded AFTER I load the html content.

I have a directive called ng-map, where if this attribute appears on any div with an ID, it'd call mapquest to fill in the div with an interactive map. Currently this works.

However, if I move the directive:

<div ng-map id="map"></div>

out of main.html and place it into submain.html and add this in my main.html:

<div ng-include="'view/submain.html'">

it doesn't work, even though my submain.html loads properly.

It gives me the error: "Error: Object # has no method 'initMap'"

This is what my directive looks like:

mapapp.app.directive('ngMap', ['logger', '$http', function (logger, $http) {
    var directiveDefinitionObject = {
        restrict: 'A',
        controller: function link($scope, $element) {
            $scope.shouldMapLoadOnPageLoad = true;

            $scope.loadCodeAndMap =
                function () {
                    var key = {...};
                    var script = document.createElement('script');
                    script.type = 'text/javascript';
                    script.src = "http://www.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?key=" + key;
                    document.body.appendChild(script);
                };
            $scope.loadCodeAndMap();
            $scope.initMap = function () {
               ...
            }
        }
    };
    return (directiveDefinitionObject);
}]);

Any help in understanding what is happening here is appreciated.

share|improve this question
 
where is the module in the DOM mapapp.app in relation to main.html? –  koolunix 21 hours ago
 
the error seems to be coming from whoever is calling $scope.initMap(), so... can you share, where is that call coming from? –  guzart 21 hours ago
 
Well the path of my script doesn't matter since I put everything in a bundle.config, which gets saved in a virtual folder, this is specific to webapi mvc 5, so it's not a matter of where, but a matter of when. The javascript loads up just fine since I was able to place a breakpoint in the file during the page load, and it hit it successfully. –  sksallaj 21 hours ago
 
the #scope.initmap is called from the controller for this view. So when I change a dropdown selection, then that $scope.initMap is called. Again, it works if that div is in main.html, but not in submain.html with main.html including that. –  sksallaj 21 hours ago
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.