MMR
MMR

Reputation: 3009

How to call a file in controller

I have a file in which ii declared my videouploadfolder url and i want to call that file in my js my config.js

var filepath = {
       uploadVideoUrl : './public/videos'
}

I called it in my node.js as

var config = require(config);
     config.uploadVideoUrl;

But i am not sure how to call in js,can anyone suggest help please.Thanks.

Upvotes: 0

Views: 51

Answers (2)

Bala Abhinav
Bala Abhinav

Reputation: 1348

  1. If you want your config.js file to stay only in server where you have ther services editing it, then you would have to write a REST route in nodeJs to fetch the content of the config and send it back to angularJS client.
  2. If you dont mind saving that config json in your client side itself instead of your server then follow what Sajeetharan has said.

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222582

With angularjs you can make use of constant,

 var app = angular.module('configuration', [])
    .constant('uploadVideoUrl', './public/videos')

Then you can use in your controller as,

app.controller('Ctrl1', ['$scope','uploadVideoUrl'
    function ($scope,'uploadVideoUrl') {
       var config = uploadVideoUrl;
    }
]);

Upvotes: 1

Related Questions