angular.js - When adding Amap API to angularjs, the map display is not normal and the console reports an error. What is the solution?
PHP中文网
PHP中文网 2017-05-15 16:57:54
0
2
771

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中文网

认证0级讲师

reply all(2)
给我你的怀抱
var map = new AMap.Map('container');

Put this map console out and take a look

仅有的幸福

Isn’t this a scope issue?

And also, angular runs after window.onload

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template