0

I want to remove all hard codings in angular controller, For that I want to load all hot codings from another js file, For Example

modalHeader = "Success";

Here Success is a Hot coding. So I want to load this success from out side js file. In Js controller I want to give key of the success,instead of "Success", I reffered many articals But there is no useful for this scenario.Please give some info to proceed like this,as I am fresher to angularJS

Thanks in advance.

1
  • see my answer @ShivaGoudA Commented Mar 12, 2017 at 10:21

1 Answer 1

1

You can use constants for this . Constant values can be accessed all over the application . You just inject the constant into controller or service to use.

Define constants or values

var app = angular
  .module('test');

app.constant("ENV", {
  "CON1": "val1",
  "CON2": "val2",
  "CON3: "val3",
});

And use in service

angular.module('test')
  .service('testService', function ($http, ENV)

or in controller

 angular.module('test')
  .controller('testController ', function ($http, ENV)

values are accessible via ENV.CON1

Sign up to request clarification or add additional context in comments.

4 Comments

what is the extention for the constant file
simple js file liek any other js you can use it .. mark as accepted if this helps :) @ShivaGoudA
I am getting ENV dependency problem BOSS
you missed something.. post another question with that

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.