0

我正在尝试将 Yandex Maps 与此 AngularJS模块一起使用。他们在这里有演示,这是我的代码:

索引.html

  <!DOCTYPE html>
<html lang="ru" xmlns:vml="urn:schemas-microsoft-com:vml" ng-app="myApp" ng-controller="myController">
<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1" />
    <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
    <link rel="stylesheet" href="style.css">

    <script src="angular.min.js"></script>
    <script src="ya-map-2.1.min.js"></script>


    <script src="script.js" type="text/javascript"></script>
</head>
<body>

     <div id="map" class="w3-col s10 w3-dark w3-border">    
        <!-- 
         <ya-map ya-zoom="8" ya-center="[37.64,55.76]" style="width:400px;height:500px;"></ya-map>
         -->
     </div>

</body>
</html>

脚本.js

console.log("script starts");

var myApp = angular
    .module('myApp', ['yaMap'])
    .controller("myController", function ($scope) {
        console.log("In the controller");
        var _map;


        $scope.afterMapInit = function (map) {
            _map = map;
        };
        $scope.del = function () {
            _map.destroy();
        };

        console.log("After $scope ops");

        $scope.initialize = function () {
            var mapOptions = {
                center: [50.5, 30.5],
                zoom: 8
            };
            ymaps.ready(function () {
                $scope.map = new ymaps.Map("map", mapOptions);
            })
        }
    });

样式.css

body {
    background-color: #fff;
    margin: 40px;
}

#body {
    margin: 0 15px 0 15px;
}

#frmMain {
    width: 100%;
    height: 100%;
}

请,如果您知道为什么我无法加载地图以及该代码有什么问题(我想这一切都是错误的),请告诉我!

我完全是 AngularJS 和 Yandex Maps 的新手,所以,这对你来说可能是一个愚蠢的问题,但我在 Internet 上找不到任何有用的东西。

4

1 回答 1

1

非标准标签的风格问题ya-map。默认情况下,浏览器将其显示属性设置为“内联”,因此没有文本元素折叠到宽度:0,高度:0。

此外,您不要使用控制器中声明的任何函数。

您可以在演示页面中查看示例

var myApp = angular
  .module('myApp', ['yaMap'])
  .controller("myController", function($scope) {
    var _map;

    $scope.afterMapInit = function(map) {
      _map = map;
    };
    $scope.del = function() {
      _map.destroy();
    };

  });
ya-map {
  display: block;
  width: 400px;
  height: 500px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
<script src="//rawgit.com/tulov/angular-yandex-map/master/ya-map-2.1.min.js"></script>

<div id="map" class="w3-col s10 w3-dark w3-border" ng-app="myApp" ng-controller="myController">
  <ya-map ya-zoom="8" ya-center="[37.64,55.76]" ya-after-init="afterMapInit($target)"></ya-map>
  <button ng-click="del()">Удалить</button>
</div>

于 2016-04-22T07:50:04.180 回答