我已经在Stack上阅读了很多类似的问题,但我还没有能够解决我的问题。我有一个角度模块和控制器,它在之前工作正常我包含了jQuery库。当我包含它时(包括angular lib之前),我得到了
Error: $scope.markersEvent is undefined
并且在控制器中我有console.log($)我得到
function jQuery()
我的理解是,如果我在 jQuery之后包含Angular ,那么应该没有冲突,因为Angular"需要" $。不过,我试过了
<script type="text/javascript">var j = $.noConflict();</script>
并且console.log($)将显示
undefined
我应该怎样做才能让使用$和jQuery使用Angular,比方说,jq?抱歉,我是Angular的新人。
代码: 的index.html
<link rel="shortcut icon" href=""><!-- for removing favicon error -->
<!-- script references -->
<script src="externals/jquery/jquery-1.12.1.js"></script>
<script type="text/javascript">var j = $.noConflict();</script>
<script src="externals/angularjs/lodash.js"></script>
<script src="externals/angularjs/angular.js"></script>
<script src="externals/angularjs/angular-ui-router.js"></script>
<script src="externals/angularjs/angular-animate.js"></script>
<script src="externals/angularjs/angular-simple-logger/dist/angular-simple-logger.js"></script>
<script src="externals/angularjs/angular-google-maps.js"></script>
<script src="app/app.js"></script>
<script src="app/components/partials/eventJoin/eventJoin.module.js"></script>
<script src="app/components/partials/eventCreate/eventCreate.module.js"></script>
<script src="app/components/directives/header-menu/header-menu.module.js"></script>
<script src="app/components/directives/header-login/header-login.module.js"></script>
<script src="app/components/directives/event-type-choose/event-type-choose.module.js"></script>
<script src="app/components/directives/sidebar-event-list/sidebar-event-list.module.js"></script>
eventJoin.module.js
angular.module('eventJoin.module', [])
//controller start
.controller('eventJoinController', function ($scope) {
angular.element(document).ready(function () {
//run when DOM is ready
console.log($);
initMap();
for (i = 0; i < $scope.markersEvent.length; i++) {
initMarkers($scope.markersEvent[i]); //create initial markers
}
});
//Pre-load document.ready
function initMap() {
$scope.mapProp = {
//karta över sverige
center : {
lat : 62.5421031,
lng : 19.7477994
},
zoom : 5,
};
$scope.map = new google.maps.Map(document.getElementById('googlemap'), $scope.mapProp);
}
function initMarkers(info) {
console.log("initMarkers function");
new google.maps.Marker({
map : $scope.map,
position : new google.maps.LatLng(info.lat, info.lang),
title : "test"
});
}
$scope.markersEvent = [{
city : 'Göteborg',
desc : 'This is the best city in the world!',
lat : 57.716610,
lang : 11.973904
}, {
city : 'Stockholm',
desc : 'Shit city',
lat : 59.336574,
lang : 18.067879
}, {
city : 'Kiruna',
desc : 'Shit city',
lat : 67.858475,
lang : 20.225530
}
];
})
//END controller
app.js
var myApp = angular.module('app', ['ui.router', 'eventJoin.module', 'eventCreate.module', 'header-menu.module',
'header-login.module', 'event-type-choose.module', 'sidebar-event-list.module']);
myApp.controller('appController', function() {
var appCont = this;
appCont.shit = "hhh";
});
答案 0 :(得分:0)
change
中没有Event
JS文件作为eventJoin.module.js
。包括它,它应该工作。
答案 1 :(得分:0)