Skip to content Skip to sidebar Skip to footer

Angularjs - Dynamically Adding Value In Module.config

var app = angular.module('myApp',['ui.router','flow']); app.config(['flowFactoryProvider', function (flowFactoryProvider) { flowFactoryProvider.defaults = { tar

Solution 1:

Two possible ways I can think of:

Import $rootScope and set it there:

var app = angular.module("myApp",['ui.router','flow']);
    app.config(['flowFactoryProvider', function (flowFactoryProvider, $rootScope) {
        flowFactoryProvider.defaults = {
            target: 'upload.php?type=' + $rootScope.vtype,
            testChunks:false,
            singleFile: true,
            permanentErrors: [404, 500, 501],
            maxChunkRetries: 1,
            chunkRetryInterval: 5000,
            simultaneousUploads: 4
        };  
    }
]);

and in some controller, you can set it as

$rootScope.vtype = something;

OR you could write a get/set method inside the provider which would allow you to change a local value.

var app = angular.module("myApp",['ui.router','flow']);
    app.config(['flowFactoryProvider', function(flowFactoryProvider) {

        var someLocalValue = 1; // default value

        flowFactoryProvider.defaults = {
            target: 'upload.php?type=' + someLocalValue,
            testChunks:false,
            singleFile: true,
            permanentErrors: [404, 500, 501],
            maxChunkRetries: 1,
            chunkRetryInterval: 5000,
            simultaneousUploads: 4
        };  
        flowFactoryProvider.getSomeLocalValue = function(){
            return someLocalValue;
        };
        flowFactoryProvider.setSomeLocalValue = function(input){
            flowFactoryProvider.defaults.target = 'upload.php?type=' + input;
            someLocalValue = input;
        };
    }
]);

Post a Comment for "Angularjs - Dynamically Adding Value In Module.config"