search

Home  >  Q&A  >  body text

angular.js - When adding Amap API to angularjs, the map display is not normal and the console reports an error. What is the solution?


angular.module('drApp', ['ng', 'ngRoute', 'ngAnimate'])
.controller('startCtrl', ['$scope',function ($scope) {
var map = new AMap.Map('container');
            map.setZoom(16);
            map.setCenter([116.397428, 39.90923]);
      var marker = new AMap.Marker({
                position: [116.397428, 39.90923],
                map: map
            });
            
  }]);

Error message: Uncaught ReferenceError: map is not defined

The map printed by the console:

Error purchasing source:

PHP中文网PHP中文网2811 days ago797

reply all(2)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-15 16:59:54

    var map = new AMap.Map('container');

    Put this map console out and take a look

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-15 16:59:54

    Isn’t this a scope issue?

    And also, angular runs after window.onload

    reply
    0
  • Cancelreply