Question regarding the utilization of two-way binding in AngularJS and Rails ERB files.
Let's say the input value in my .erb file has an initial value like this:
example.erb
<input type="text" value=" <%= @item.title %> " ng-model ="item.title">
As evident in the above example, the input is also connected to an AngularJS model. example.js
mayApp.controller('newItemController', function itemController($scope) {
$scope.item = {title:"angularJs model value", price: 1000}
}
I noticed that the original @item.title gets replaced by the AngularJS model value. But I want the opposite to happen, where the AngularJS model is initialized with the value from the .erb file. How can I achieve that?
I attempted to include example.js in the asset pipeline. i.e. example.js.erb
mayApp.controller('newItemController', function itemController($scope) {
$scope.item = {title:"<%= @item.title %>", price: 1000}
}
However, the @item always seems to be nil in the pipeline. Is it possible that @item is only accessible in views?