我正在尝试在ng-view中添加简单地图,但该地图不会显示。
有什么办法使其弹出?我找不到解决方案。

这是我的代码

index.html

<html lang="en" ng-app="myApp" >
<head>
  <link rel="icon"
      type="image/png"
      href="icon128-2x.png">
  <meta charset="utf-8">
  <!--<meta http-equiv="X-UA-Compatible" content="IE=edge">

  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">-->
  <title>My AngularJS App</title>
  <!--<link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/normalize.css">
  <link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/main.css">-->
  <link rel="stylesheet" href="app.css">
  <link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
  <script src="bower_components/html5-boilerplate/dist/js/vendor/modernizr-2.8.3.min.js"></script>

<link rel="stylesheet" href="css/userprofile.css">
  <style>
    input {
    text-align: center;
}
  </style>
  <img src="img\banner.jpg" class="img-responsive" alt="Cinque Terre"style="width: 100%; height: 350px;" >
</head>
  <body style="background-color:#ff884d;">


  <!--div class="jumbotron" style="background-color:lightblue;">
  <h1>Bootstrap Tutorial</h1>
  <p>Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile-first projects on the web.</p>
</div-->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Thaishop Online</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#!/view1">หน้าหลัก <span class="sr-only">(current)</span></a></li>
        <li ng-controller="ManageuserController" ng-init="getuser()"><input type="hidden"  type="text" ng-model="usercontent">
          <a ng-model="usercontenttt" ng-hide="!usercontent" href="#!/{{userpage}}">โปรไฟล์ของคุณ</a></li>
       <!--<li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <!--<form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>-->
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#!/view2">สมัครสมาชิก</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li ng-controller="ManageuserController" ng-init="getuser()">
          <input type="hidden"  type="text" ng-model="usercontent">
          <a ng-show="!usercontent" href="#!/viewLogin">เข้าสู่ระบบ</a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
<!--<input ng-model="somefield">
<span ng-show="!somefield">Sorry, the field is empty!</span>
<span ng-hide="!somefield">Thanks. Successfully validated!</span>-->
</br></br>

  <div ng-view></div>




    <script src="js/jquery-2.2.3.js"></script>
<script src="js/bootstrap.min.js"></script>
  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-route/angular-route.js"></script>
  <script src="app.js"></script>
  <script src="view1/view1.js"></script>
  <script src="view2/view2.js"></script>
  <script src="viewEditcafe/viewEditcafe.js"></script>
  <script src="viewLogin/viewLogin.js"></script>
  <script src="viewUserprofile/viewUserprofile.js"></script>
   <script src="viewAdminprofile/viewAdminprofile.js"></script>
  <script src="viewSaveCafeDetail/viewSaveCafeDetail.js"></script>
  <script src="components/version/version.js"></script>
  <script src="components/version/version-directive.js"></script>
  <script src="components/version/interpolate-filter.js"></script>
<script src="viewManageuser/viewManageuser.js"></script>
<script src="viewAdminManageuser/viewAdminManageuser.js"></script>
<script src="viewAdminEditcafe/viewAdminEditcafe.js"></script>
  <script src="viewProduct/viewProduct.js"></script>
  <script src="viewProduct2/viewProduct2.js"></script>
  <script src="viewselecttheme/viewselecttheme.js"></script>
  <script src="viewSelectlocation/viewSelectlocation.js"></script>
  <link href="css/round-about.css" rel="stylesheet">
  <link href="css/portfolio-item.css" rel="stylesheet">

</body>
</html>


viewselectlocation.html

    <div id="map"></div>
        <script>
          function initMap() {
            var uluru = {lat: -25.363, lng: 131.044};
            var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 4,
              center: uluru
            });
            var marker = new google.maps.Marker({
              position: uluru,
              map: map
            });
          }
        </script>
        <script async defer
        src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBE95rVRz0viHQOBKKikYxl5WsYFROclUU&callback=initMap">
        </script>



viewSelectlocation.js


 angular.module('myApp.viewSelectlocation', ['ngRoute'])

        .config(['$routeProvider', function ($routeProvider) {
            $routeProvider.when('/viewSelectlocation', {
                templateUrl: 'viewSelectlocation/viewSelectlocation.html',
                controller: 'SelectlocationController'
            });
        }])

        .controller('SelectlocationController', function ($scope, $http, $location) {



        });

最佳答案

您可以具有控制器或链接功能,然后开始在其中实现地图。 Link functioncontroller functionjsfiddle

您可以使用解析器加载初始地图数据

关于javascript - Google Map Api不在ng-view中显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40707762/

10-10 23:07