ruby on rails - Angularjs + RubyonRails + Google Maps Error: [$injector:unpr] Unknown provider: tProvider <- t -
iam creating app angulajs , rubyon rails.i want show google maps user partiular latituts , longitude gettig kind of error
here code.
angularjs directive code
app.directive('map', function() { return { restrict: "a", template: "<div id='areamap'></div>", scope: { area: "=", zoom: "=" }, controller: function ($scope) { var mapoptions; var map; var marker; var initialize = function () { mapoptions = { zoom: $scope.zoom, //center: new google.maps.latlng(40.0000, -98.0000), maptypeid: google.maps.maptypeid.terrain }; map = new google.maps.map(document.getelementbyid('areamap'), mapoptions); }; var createmarker = function (area) { var position = new google.maps.latlng(area.latitude, area.longitude); map.setcenter(position); marker = new google.maps.marker({ map: map, position: position, title: area.name }); }; $scope.$watch("area", function (area) { if (area != undefined) { createmarker(area); } }); initialize(); }, }; });
controller
function eventdetailsctrl($scope, $http, $location, $routeparams, $sce) { var event_id = $routeparams.event_id var url = 'api_url_for_json'; $http.jsonp(url).success(function(data) { $scope.event = data; $scope.area = { name: "melbourne", latitude: data.event.latitude, longitude: data.event.longitude }; $scope.latitude = data.event.latitude; $scope.longitude = data.event.longitude; }); }
view file
<div ng-controller ="eventdetailsctrl"> <div map area="area" zoom="20"></div> </div>
==============================================================
how can resolve issue.pls in advance.
there syntax error in creating controller should be:
app.controller('eventdetailsctrl',['$scope','$http','$location','$routeparams','$sce',function($scope, $http, $location, $routeparams, $sce) { var event_id = $routeparams.event_id var url = 'api_url_for_json'; $http.jsonp(url).success(function(data) { $scope.event = data; $scope.area = { name: "melbourne", latitude: data.event.latitude, longitude: data.event.longitude }; $scope.latitude = data.event.latitude; $scope.longitude = data.event.longitude; }); }]);
and remember boostrap angular using ng-app in html markup (if have not done that).
it may happen minify js files. if minify controller without injecting dependencies give syntax error, best use proper syntax write controller having dependencies injected done above.
Comments
Post a Comment