How did AngularJS return the value to an integer?

I am using nested form and AngularJS and I have this in my code.

#app/view/customer_templates/edit.html.erb
<%= f.simple_fields_for :customer_template, @customer.customer_template.build, child_index: '{{$index}}' do |t| %>
  <%= t.select :field_type_id, options_from_collection_for_select(FieldType.all, :id, :name, '{{customer_template.field_type_id}}') %>      
<% end %>

      

My choice works, but doesn't get the current data field_type_id

.

{{customer_template.field_type_id}}

from angular is returning correct data, but this is a string when i tried to convert it to integer, for example the {{customer_template.field_type_id}}.to_i

result is 0 . I also tried passing this to a variable and converting it, but I get the same result.

I've also tried this {{parseInt(customer_template.field_type_id)}}

in my angularjs too $scope.parseInt = parseInt

, but no luck.

This is my problem below.

enter image description here

I must have 1-Checkbox, 2-Dropdown (Yes / No) and 2-Textbox, can you help me? I'm a noob in AngularJS. My only problem is the value I will put inside options_from_collection_for_select

. If I can fit an integer it works.

+3


source to share


1 answer


Have you tried converting shorthand to javascript?

{{+customer_template.field_type_id}}

      



And in your controller:

$scope.parseInt = +parseInt;

      

+1


source







All Articles