我有產生谷歌地圖一個指令:
directive('gMap', function(googleMaps){
return{
restrict: 'E',
replace: true,
transclude: true,
template: "<div ng-transclude></div>",
scope: true,
link: function(scope, element, attrs){
scope.$on('location', function(){
//här ska den recentreras
})
//create the map
var center = googleMaps.makePosition(attrs.centerlat, attrs.centerlong)
//update map on load
var options = googleMaps.setMapOptions(center, attrs.zoom);
scope.map = googleMaps.createMap(options, attrs.id)
//googleMaps.addMarker(map, center,'Hello')
},
controller: ['$scope', function($scope) {
console.log($scope);
}]
};
}).
當我console.log($scope)
,它輸出包含節點地圖的對象。 當我嘗試console.log($scope.map)
它輸出undefinded
,爲什麼呢?
奇怪的是,如果我在$超時包裝它這個工程:0 – Himmators