AngularJs将工厂注入控制器 [英] AngularJs injecting factory into controller

查看:197
本文介绍了AngularJs将工厂注入控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



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

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();
});



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




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

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

});





提前致谢。



Thanks in advance .

推荐答案

范围,


modal,modelHelper){

});
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));


这篇关于AngularJs将工厂注入控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆