这里是AngularJS的新手。我想在私有函数中使用一段工厂代码(logger),如下所示,这可能吗? 我仍在努力掌握角度概念。感谢:
(function () {
'use strict';
angular
.module('app.admin')
.controller('UploadController', UploadController);
UploadController.$inject = ['$scope', 'FileUploader', 'dataservice', 'logger', 'config'];
function UploadController($scope, FileUploader, dataservice, logger, config)
{
...
logger.info('blah blah blah', 'Error!');
...
SomeFunction();
...
}
//private function
function SomeFunction()
{
//... code hidden for brevity
$.ajax({
type: "POST",
url: url,
async: true,
cache: false,
data: dataString,
success: function(results)
{
//need to use the 'logger' factory here
//logger.info('blah blah blah', 'Error!'); <= this wont work
}
});
}
})();
谢谢
答案 0 :(得分:1)
试试这个:
function SomeFunction(logger)
{
$.ajax({
type: "POST",
url: url,
async: true,
cache: false,
data: dataString,
logger: logger,***************
success: function(results)
{
//need to use the 'logger' factory here
//logger.info('blah blah blah', 'Error!'); <= this wont work
}
});
SomeFunction(logger);