我正在使用Visual Studio 15,尝试运行一个cordova标签模板项目。我只是想在我的tab-map.html上加载谷歌地图,但我收到以下错误:
3z
这是我的tab-map.html:
TypeError: $scope.init is not a function
at new <anonymous> (http://localhost:4400/js/controllers.js:22:12)
at Object.instantiate (http://localhost:4400/lib/ionic/js/ionic.bundle.js:18010:14)
at $controller (http://localhost:4400/lib/ionic/js/ionic.bundle.js:23412:28)
at self.appendViewElement (http://localhost:4400/lib/ionic/js/ionic.bundle.js:59900:24)
at Object.render (http://localhost:4400/lib/ionic/js/ionic.bundle.js:57893:41)
at Object.init (http://localhost:4400/lib/ionic/js/ionic.bundle.js:57813:20)
at self.render (http://localhost:4400/lib/ionic/js/ionic.bundle.js:59759:14)
at self.register (http://localhost:4400/lib/ionic/js/ionic.bundle.js:59717:10)
at updateView (http://localhost:4400/lib/ionic/js/ionic.bundle.js:65398:23)
at http://localhost:4400/lib/ionic/js/ionic.bundle.js:65375:11
和我的controller.js,这个控制器位于js文件的中间,所以最后没有分号
<ion-view view-title="Map">
<ion-content class="padding">
<ion-refresher (ionRefresh)="doRefresh($event)">
<ion-refresher-content
pullingIcon="arrow-dropdown"
pullingText="Pull to refresh"
refreshingSpinner="circles"
refreshingText="Refreshing...">
</ion-refresher-content>
</ion-refresher>
<h2 align="center">Map</h2>
<div id="map" data-tap-disabled="true"></div>
</ion-content>
<ion-footer-bar class="bar-dark">
<a ng-click="centerOnMe()" class="button button-icon icon ion-navigate">Find Me</a>
</ion-footer-bar>
</ion-view>
答案 0 :(得分:0)
编写init函数,如下所示
$scope.init = function () {}
而不是
$scope.init() = function () {}
答案 1 :(得分:0)
所以我能够通过VS 2015在仿真中显示地图。在tab-map.html中我添加了ng-init =&#34; init()&#34;
<ion-content class="padding" ng-init="init()">
<h2 align="center">Map</h2>
<div id="map" data-tap-disabled="true"></div>
</ion-content>
现在尝试在移动设备上运行时出现此错误:
"ReferenceError: google is not defined
at Scope.$scope.init (file:///android_asset/www/js/controllers.js:24:28)
at fn (eval at compile (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:27638:15), <anonymous>:4:203)
at Scope.$eval (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:30395:28)
at pre (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:39095:15)
at invokeLinkFn (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:22993:9)
at nodeLinkFn (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:22371:11)
at compositeLinkFn (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:21703:13)
at nodeLinkFn (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:22387:24)
at compositeLinkFn (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:21703:13)
at publicLinkFn (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:21583:30)"
指的是以下一行:
var myLatlng = new google.maps.LatLng(35.182217, -83.381418);