我想在'我的網站'角度谷歌地圖'標記'。角度谷歌地圖主控制器錯誤
這裏是我使用的代碼: 控制器main.js
angular.module('dashyAppApp')
.factory("Markers", function(){
var Markers = [
{
"id": "0",
"coords": {
"latitude": "45.5200",
"longitude": "-122.6819"
},
"window": {
"title": "Portland, OR"
}
},
{
"id": "1",
"coords": {
"latitude": "40.7903",
"longitude": "-73.9597"
},
"window" : {
"title": "Manhattan New York, NY"
}
}
];
return Markers;
});
.controller('MainCtrl', function ($scope,Markers) {
$scope.map = {
center: { latitude: 39.8282, longitude: -98.5795 },
zoom: 4
};
$scope.markers = Markers;
});
,這裏是我的看法main.html中
<ui-gmap-google-map
center='map.center'
zoom='map.zoom' aria-label="Google map">
<ui-gmap-marker ng-repeat="marker in markers"
coords="marker.coords" options="marker.options" events="marker.events" idkey="marker.id">
<ui-gmap-window>
<div>{{marker.window.title}}</div>
</ui-gmap-window>
</ui-gmap-marker>
</ui-gmap-google-map>
我不斷收到此錯誤:
markerwithlabel.js:71 Uncaught ReferenceError: google is not defined(anonymous function) @ markerwithlabel.js:71
infobox.js:116 Uncaught ReferenceError: google is not defined(anonymous function) @ infobox.js:116
keydragzoom.js:820 Uncaught ReferenceError: google is not defined(anonymous function) @ keydragzoom.js:820(anonymous function) @ keydragzoom.js:861
richmarker.js:60 Uncaught ReferenceError: google is not defined(anonymous function) @ richmarker.js:60
main.js:37 Uncaught SyntaxError: Unexpected token .
angular.js:13708 Error: [ng:areq] Argument 'MainCtrl' is not a function, got undefined
http://errors.angularjs.org/1.5.7/ng/areq?p0=MainCtrl&p1=not%20aNaNunction%2C%20got%20undefined
at http://localhost:9000/bower_components/angular/angular.js:68:12
at assertArg (http://localhost:9000/bower_components/angular/angular.js:1885:11)
at assertArgFn (http://localhost:9000/bower_components/angular/angular.js:1895:3)
at $controller (http://localhost:9000/bower_components/angular/angular.js:10210:9)
at Object.<anonymous> (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:4095:28)
at http://localhost:9000/bower_components/angular/angular.js:1240:18
at invokeLinkFn (http://localhost:9000/bower_components/angular/angular.js:9814:9)
at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:9215:11)
at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:8510:13)
at publicLinkFn (http://localhost:9000/bower_components/angular/angular.js:8390:30)
我不知道爲什麼它不會工作,對於一個'谷歌沒有定義的錯誤'剛剛出來因爲當我只顯示一個沒有.factory的標記時,地圖顯示的很好。
你能設置一個jsfiddle鏈接,以便我可以幫助調試嗎? –
您沒有在控制器方法中使用$ scope。像這樣使用 .controller('MainCtrl',function($ scope){ // }); –
@DurgpalSingh有範圍.controller('MainCtrl',函數($範圍,標記) –