作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的 rails 应用程序中加载一个空白的谷歌地图应用程序(稍后我将通过 facotries 等添加标记)。这种格式在我的上一个项目中有效,但不幸的是这次我无法加载它。
我通过 bower install angular
使用 Bower ,但似乎我设置了一个错误 Error: [ng:areq] Argument 'MapController' is not a function, got undefined
从浏览器中用红线显示 map 应位于的位置。它确保所有 namespace 都匹配,但仍然不足。
同样奇怪的是这个ng:areq
错误来自公共(public) Assets 文件,而不是下面的文件(文件 application-1f030c1aa52b19b22da2952dccdcd4ba.js:6
)
错误
控制台错误:var injector = angular.injector(['Sessions_Map', 'ng']);
返回 undefined
MapController
返回 MapController is not defined
Error: [ng:areq] Argument 'MapController' is not a function, got undefined
http://errors.angularjs.org/1.3.15/ng/areq?p0=MapController&p1=not%20a%20function%2C%20got%20undefined
at application-dc67be4c50a7a0828f3e243f50780c24.js:42
at Mt (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at _t (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at application-dc67be4c50a7a0828f3e243f50780c24.js:42
at application-dc67be4c50a7a0828f3e243f50780c24.js:42
at x (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at vt (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at g (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at g (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at application-dc67be4c50a7a0828f3e243f50780c24.js:42(anonymous function) @ application-dc67be4c50a7a0828f3e243f50780c24.js:42
config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components')
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require angular
//= require map_app.js
var Sessions_Map = angular.module('Sessions_Map' , []);
Sessions_Map.controller('MapController', function($scope){
});
Sessions_Map.directive("myMaps", function() {
return {
restrict: 'E',
template: '<div></div>',
replace: true,
link: function (scope, element, attrs) {
var mapOptions = {
center: new google.maps.LatLng(34.029732, -118.449528),
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(attrs.id), mapOptions);
}
};
});
<!doctype html>
<html ng-app="Sessions_Map">
<head>
<%= javascript_include_tag "map_app.js", "data-turbolinks-track" => true %>
<title>
Google Maps
</title>
<style>
#map-canvas{
height:650px;
width:1050px;
border:2px solid red;
}
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAcRGSjkX4Meav-RxEzY4SXQnVwKnedZvE">
</script>
<script type="text/javascript"></script>
</head>
<body ng-controller="MapController">
<my-maps id="map-canvas"></my-maps>
</body>
</html>
最佳答案
application-dc67be4c50a7a0828f3e243f50780c24.js
config.assets.paths << Rails.root.join("...stuff...")
requires
数组)
var Sessions_Map = angular.module('Sessions_Map' , []); // create
var Sessions_Map = angular.module('Sessions_Map'); // retrieve
<script type="text/javascript"
src="/app/assets/javascripts/angular-animate.min.js.map">
</script>
<script type="text/javascript"
src = "/app/assets/javascripts/app/map_app.js">
</script>
<%= javascript_include_tag "application.js", "data-turbolinks-track" => true %>
//= require angular-animate
//= require app/map_app
Mt
,
_t
,
v
和
g
我可以看到正在缩小。
Error: [ng:areq] Argument 'MapController' is not a function, got undefined
http://errors.angularjs.org/1.3.15/ng/areq?p0=MapController&p1=not%20a%20function%2C%20got%20undefined
at application-dc67be4c50a7a0828f3e243f50780c24.js:42
at Mt (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at _t (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at application-dc67be4c50a7a0828f3e243f50780c24.js:42
at application-dc67be4c50a7a0828f3e243f50780c24.js:42
at x (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at vt (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at g (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at g (application-dc67be4c50a7a0828f3e243f50780c24.js:42)
at application-dc67be4c50a7a0828f3e243f50780c24.js:42(anonymous function) @ application-dc67be4c50a7a0828f3e243f50780c24.js:42
uglifier
进入您的 Rails 配置以查看结果
application-[checksum].js
,并实际看到您的 Controller 在那里。
WARNING: Tried to load angular more than once.
关于angularjs - 错误 : [ng:areq] Argument Controller is Not a Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29645769/
我是一名优秀的程序员,十分优秀!