0

Here is my one main angular module with constant defined on it.

/// <reference path="../../../thirdparty/angular/angular.d.ts"/>
var FeatureFlagsValues: ng.IModule = angular.module('feature-flags.values', []);
 FeatureFlagsValues.constant('FeatureFlagValues', {});
 FeatureFlagsValues.run(['$q', '$http', 'FeatureFlagValues', function (_q:ng.IQService, _http: ng.IHttpService, FeatureFlagValues: any) {
let deferred = _q.defer();
let uri = "/api/v1/features/user";

_http.get(uri)
    .success(function (data) {
        deferred.resolve(data);
    })
    .error(function (data, status) {
        deferred.reject({data,status});
    });

deferred.promise.then((results: any) => {
    angular.forEach(results.EnabledFlags, function (key) {
        FeatureFlagValues[key] = true;
    });
});
deferred = _q.defer();
uri = '/api/v1/features/user?defaults=true';

_http.get(uri)
    .success(function (data) {
        deferred.resolve(data);
    })
    .error(function (data, status) {
        deferred.reject({ data, status });
    });
deferred.promise.then((defaultResults: any) => {
    angular.forEach(defaultResults.EnabledFlags, function (key) {
        FeatureFlagValues[key] = true;
    });
 });

}]);

Here is my another angular module in which I want use the constant defined in previous module, I am not sure how can i do that. I did research couldn't find any good example.

 // <reference path="./FeatureFlags.values.ts"/>
 import {Endpoints as endpoints} from '../../endpointsTsModule';
 import {FeatureFalgs as FF}  from './FeatureFlags.service.SettingStore';

 export module FeatureFlags.service {
 export class FeatureFlagsService {
 static $inject: string[] = ["$q", "$http", "feature-flags.values","FeatureFlagsSettingStore"];
   }
}

1 Answer 1

0

If you want to use the 'FeatureFlagValues' constant you need to make the 'feature-flags.values' module a dependency of the "another angular module" you are referring to. Like so:

angular.module('another', ['feature-flags.values']);

Then you can access it in your service by just injecting it like so:

 export class FeatureFlagsService {
     static $inject: string[] = ["$q", "$http", "FeatureFlagValues","FeatureFlagsSettingStore"];
   }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.