0

my $http post body is too large and i need to make six different $http calls with different post content. i can't keep the body of the post messages (which is nothing but a valid json string) in my controller.js as it bloats it and becomes ugly. is there anything like require in javascript (or) import statements in python that i can use to put all constants in one module and import it into my app.js?

lib.js contents::::::::

var a = 'hello~' module.exports = a

app.js::::::

a = require('lib')
app.controller('aController', function($scope){
console.log(a) //this must print hello~
}

2 Answers 2

1

I don't know if I understood well, but the solutions it's to add the 'lib.js' to the HTML before you add the app.js. Like this:

<script src="js/lib.js"></script>
<script src="js/app.js"></script>

And it's not necessary to make the export, you 'lib.js' may look like that:

var a="hello";

And in your app.js put console.log(a)

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

Comments

0

You can create a module that holds constants and is included in your js build process and use $provide.constant('constantName', constantObj); to provide the value. then you can just import the module and then the provider in your controller by doing:

app.module('this.aController', ['constantsModule']);
app.controller('aController', [
  'constantName',
  '$scope',
  function ($scope) {
    console.log(a);
  } 
]);

Comments

Your Answer

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