Angularjs + Yandex 地图

Angularjs + Yandex Maps

我正在尝试将 Yandex 地图与此 AngularJS module 结合使用。 这里有 demonstrations,这是我的代码:

index.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>

script.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);
            })
        }
    });

style.css

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

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

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

拜托,如果你知道为什么我不能加载地图以及代码有什么问题(虽然我想这都是错误的),请告诉我!

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

非标准标签的样式存在问题 ya-map。默认情况下,浏览器将其显示 属性 设置为 "inline",因此没有文本元素会折叠为 width:0、height:0.

此外,您没有使用在控制器中声明的任何函数。

您可以在 Demo Page

中查看示例

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>