我有两个模块:第一个模块用于 map ,另一个模块用于支付。 我想在付款中显示 map 上两点 A 和 B 之间的方向。
我想知道如何在支付中注入(inject) map 的模块或 Controller
'use strict';
(function () {
'use strict';
var module = angular.module('etaxi.main');
module.controller('HomeCtrl', HomeCtrl);
//Controller of map
function HomeCtrl($scope, $rootScope, $timeout, $ionicPopup, uiGmapGoogleMapApi, $http, $log, $document) {
//...
})();
支付 Controller
'use strict';
(function () {
'use strict';
var module = angular.module('etaxi.payment');
module.controller('PaymentCtrl', PaymentCtrl);
function PaymentCtrl($scope, $ionicModal, $ionicLoading, $timeout, uiGmapGoogleMapApi) {
//...
})();
最佳答案
在你的情况下,你不应该使用 implicit-annotation ,但你可以尝试 $inject-property-annotation或内联数组注释。所有这些方法都在官方文档中:AngularJS Dependency Injection .
您的代码:
var module = angular.module('etaxi.payment', ['etaxi.main']);
module.controller('PaymentCtrl', PaymentCtrl);
var PaymentCtrl = function($scope, $ionicModal, $ionicLoading, $timeout, uiGmapGoogleMapApi, etaxiMain) {
...
}
PaymentCtrl.$inject = ['$scope', '$ionicModal', '$ionicLoading', '$timeout', 'uiGmapGoogleMapApi', 'etaxi.main'];
UPD:忘记添加:var module = angular.module('etaxi. payment', ['etaxi.main']);
(已修复)。
关于javascript - 将模块注入(inject)另一个模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35926207/