javascript - 将模块注入(inject)另一个模块

标签 javascript angularjs

我有两个模块:第一个模块用于 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/

相关文章:

javascript - 返回 false 不适用于 jquery 中的表单提交

javascript - angularjs 使用 .map 不是一个函数

json - Angularjs - $http 发布数据中的等号

javascript - 如何在 AngularJS e2e 测试中测试拖放功能

javascript - PouchDB:返回query()结果对象

javascript - 如果在异步函数中调用 "expect",Jest 异步测试会超时。有时工作。 "Async callback was not invoked within timeout specified"

javascript - 提交多个输入字段 jQuery/PHP 的最佳方式?

javascript - AngularJS $http.delete 和 $window.location.reload()

javascript - AngularJS - 创建一个 float 的向下滚动/返回顶部按钮

JavaScript:文本区域加载