Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am quite new to angular and rails. I have an app that displays a set of fields to user, filled with required values if they exist in db else a default set of values. What I want is, the user should be able to edit the fields and submit with button. So far, I am able to retrieve backend data using dependency injection as explained here: passing rails data to angular using dependency injection.
Now I want to post user filled data to rails backend. I know this might be done using $resource as explained in this question: How to add data to backend which is in rails upon clicking button in the front-end designed in angularjs?. But for that I have to design an API for retrieving data via http request. Is there no other way (like DI for retrieving data), because my code might break with too much modification?
This is my app.js code:

var app = angular.module("agreement_app", ["xeditable", "ui.bootstrap"]);

app.run(function(editableOptions) {
  editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
});

var Ctrl = function($scope, AppInitializer) {
  console.log("injection happening")
  $scope.agreement = {execution_date: agreementsAppInitializer.execution_date,
                 owner_name: agreementsAppInitializer.owner_name
  };
}
app.controller('Ctrl',Ctrl)
Ctrl.$inject = ['$scope', 'AppInitializer'];

Here is AppInitializer code:

app.service('AppInitializer', function(){
        return <%= @agreement.to_json.html_safe %>;
});
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.