2016-11-28 94 views
0

如何將外部文件中的服務「加載」/「導入」/「需要」到角度控制器中?我特指在控制器內引用外部文件,這是我在下面的組件代碼中要求控制器的方式。將外部文件中的服務「加載」到控制器中

app.js

angular.module('plantsync', []); 
require('./lighting-the-seeds'); 

照明最種子/ index.js

angular.module('lightingTheSeeds', []); 
angular.module('lightingTheSeeds').component('tickerComponent', require('./ticker.component')); 

/****Does the ref to this service need to be here?*/ 

angular.module('lightingTheSeeds').service('carbonCalcService', require('./carbon-calc.service')); 
angular.module('plantsync',['lightingTheSeeds']); 

照明最種子/ ticker.component.js

'use strict'; 
var tickerComponent ={ 

/在這裏,我可以從外部文件所需要的控制器/

controller: require('./ticker.controller'), 
    templateUrl: '/wp-content/themes/project_1/ticker.html' 
}; 

module.exports = tickerComponent; 

照明最種子/ ticker.controller.js

'use strict'; 

/我想 「需要」碳水化合物calc.service.js HERE而不是index.js/

tickerController.$inject = ['$scope', 'carbonCalcService']; 
function tickerController($scope, carboncalc) { 
    $scope.carboncalc = carboncalc; 
    //primitives pass by value, objects by reference!! remember!! 
    $scope.carbonAvoided = {'carbon':0 }; 
    $scope.carboncalc.loadAppliances($scope.carbonAvoided); 
    $scope.carboncalc.updateCarbon($scope.carbonAvoided); 
} 
module.exports = tickerController; 
+0

所以我想要做的是:tickerController $注=「$範圍」,要求(」 ./碳calc.service 「)]; – user3473817

回答

0

This

angular.module('lightingTheSeeds').service('carbonCalcService', require('./carbon-calc.service')); 

可以放在控制器文件的頂部。

現在並不那麼容易。

一起......這些都不是機器人移動...

相關問題