0

I am very new to AngularJS and SQL Server configuration issues.

I have developed AngularJS apps using ASP.NET MVC 5. Basically, the front-end is based on AngularJS and the back-end is in C#.

Once we put the apps in SQL Server, the application is working as expected. To run the application, I get the SurveyID = 1 (say) from the Web.Config file.

Right now, I want to run the same apps using a different SurveyID for multiple surveys.

a. The server folder is \\Survey with SurveyID = 1
b. The server folder is \\Survey2 with SurveyID = 2
c. The server folder is \\Survey3 with SurveyID = 3
d. The server folder is \\Survey4 with SurveyID = 4

Even though the apps put into a different folder structure, the apps always reads the root folder which happens to be \Survey with SurveyID = 1

But in the MVC Layout_Page, I am using the HTML tag I wonder if this is the cause of the root problem.

Right now, How Can I tell the angularJS apps which one is the root directory based on the Web.Config SurveyID

How can I resolve this issue? Inside MVC HOME Controller

            DataAccessSurvey data;
            int surveyID;
            public HomeController()
            {
                data = new DataAccessSurvey();
                surveyID =   Convert.ToInt32(ConfigurationManager.AppSettings["SurveyId"]);

            }

    [HttpGet]
        public ActionResult GetSurveyInfoData()
        {
            var surveyData = data.GetSurveyById(surveyID);
            var Survey = new Survey();
            //the rest of the code to populate the Survey related data
        }

In Angular Controller.jS I call the following way

    SurveyServices.getSurveyData()
                    .then(function (result) {
                        //alert("Success getSurveyData GetSurveyInfoData");
                        vm.SurveyInfo = result.data;
                   }

Please help me out. Thanks in advance.

1 Answer 1

0

Have a look at this SO answer about embedding Web.Config values in your JavaScript code. Specifically, you can register them with your AngularJS application using .constant() (docs here) and import them into your component or controller.

angular.module('myApp')
    .constant('SurveyID', <%=ConfigurationManager.AppSettings["SurveyID"] %>)
    .controller('MyCtrl', ['SurveyID', function(SurveyID) { ... }]);
Sign up to request clarification or add additional context in comments.

13 Comments

I do get the SurveyID value from the Web.Config to populate the Survey Questions. But it does not resolve my issue. I think how can I tell the apps to read the Survey ID from a different Server Folder? Thanks
I'm afraid I can't help you unless I know the folder structure and where you communicate with the API. Probably you're using $http or $resource, right?
you are correct I am using $http to get the SurveyID.
And do you mean with "different folders" that the surveyID is part of the URL? Because in that case, you can just do something like path/to/Survey${surveyID} and insert the variable like that
it is a Survey Apps. I want to run this apps for a different survey at the same time. So, IIS server has a separate folder for each survey. For each Survey, id is stored in the Web.Config. ID is not part of the URL. The root is Survey and the structure are like Survey/Survey1, Survey/Survey2, Survey/Survey3 like 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.