AngularJs将工厂注入控制器(AngularJs injecting factory into controller)

70 IT屋

Dears ,

I'm trying to do the following :

var common = angular.module('common', ['ui.bootstrap']);

var app = angular.module('app', ['common']);


(function (cr) {
    var modelHelper = function () {
        var self = this;
        self.getObjectById = function (object, key, value) {
            angular.forEach(object, function (objKey, objValue) {
                var a = 0;
            });
            return undefined;
        };
    };
    cr.modelHelper = modelHelper;
}(window.sys));


dgitCommon.factory('modelHelper', function () {
    return sys.modelHelper();
});

and its not injecting the 'modelHelper' into the controller like bellow :

app.controller("xController", function ($scope, $modal, modelHelper) {

});


Thanks in advance .
解决方案
scope,

modal, modelHelper) { });

Thanks in advance .

(function (cr) {
    var modelHelper = function () {
        var self = this;
        self.getObjectById = function (object, key, value) {
            angular.forEach(object, function (objKey, objValue) {
                var a = 0;
            });
            return undefined;
        };
return this ;/// this what i forget to code
    };
    cr.modelHelper = modelHelper;
}(window.sys));

亲爱的,



我正在尝试执行以下操作:

  var  common = angular.module('  common',[ '  ui.bootstrap']); 

var app = angular.module(' app',[' common']);


function (cr){
var modelHelper = function (){
var self = this ;
self.getObjectById = function (object,key,value){
angular.forEach(object,< span class =code-keyword> function (objKey,objValue){
var a = 0 ;
});
return undefined ;
};
};
cr.modelHelper = modelHelper;
}( window .sys));


dgitCommon.factory(' modelHelper' function (){
return sys.modelHelper();
});


并没有将'modelHelper'注入到控制器中,如下所示:



 app.controller(  xController function ($ scope,$ modal,modelHelper){

});




提前致谢。
解决方案
范围,

modal,modelHelper){

});



提前致谢。

函数(cr){
var modelHelper = function (){
var self = this ;
self.getObjectById = function (object,key,value){
angular.forEach(object, function (objKey,objValue){
var a = 0 ;
});
return undefined ;
};
返回 ; // /这就是我忘记编码
};
cr.modelHelper = modelHelper;
}( window .sys));

本文地址:IT屋 » AngularJs将工厂注入控制器