如何将参数传递给角度ui-router中的注入函数

时间:2016-03-16 15:25:25

标签: angularjs dependency-injection angular-ui

所以我有这条路由代码: -

    $stateProvider.state('app.dashboard', {
    url: "/dashboard",
    templateUrl: "app/components/dashboard/dashboard.html"
    , resolve: {
        factory: ["$ocLazyLoad", "$q", ['jquery-sparkline', 'dashboardCtrl'], loadSequence]
    },
    title: 'Dashboard',
    ncyBreadcrumb: {
        label: 'Dashboard'
    }

我有这个功能: -

function loadSequence($ocLL, $q, files) {

}

所以基本上我想做的是将['jquery-sparkline','dashboardCtrl']传递给函数loadSequence,这些值是简单的字符串值。有没有办法解决这个问题。

1 个答案:

答案 0 :(得分:0)

也许我不理解你

 (function () {
'use strict';
angular
        .module('plunker')
        .config(config);
config.$inject = ['$stateProvider'];
/* @ngInject */
function config($stateProvider) {



    $stateProvider
            .state('app.dashboard', {
                url: '/dashboard',
                templateUrl: 'app/components/dashboard/dashboard.html',
                controller: 'dashboardCtrl',
                controllerAs: 'dashboard',
                resolve: {
                    dashboardService: dashboardService
                },
                title: 'Dashboard',
                ncyBreadcrumb: {
                   label: 'Dashboard'
                                }

            });
}
dashboardService.$inject = ['$ocLazyLoad', '$q'];
function dashboardService($ocLazyLoad, $q) {
    return buttonService.getButtons().then(function (data) {
        return data;
    });
}
})();

  (function () {
    'use strict';

    angular
        .module('app.dashboard')
        .controller('dashboardCtrl', dashboardCtrl);


     dashboardCtrl.$inject = ['dashboardService','jquery-sparkline'];
      function dashboardCtrl(dashboardService,jquery-sparkline) {

      var vm = this; 
          vm.loadSequence = loadSequence;

       function loadSequence($ocLL, $q, files) {

          }
          }
           })();