Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:54:20+00:00 2026-06-13T06:54:20+00:00

I’m using AngularJS with Rails and creating dynamic nested form items which are not

  • 0

I’m using AngularJS with Rails and creating dynamic nested form items which are not registering in the AngularJS scope. They are assigned the ‘ng-dirty’ class.

I have an investor which has three houses, in my Angular controller I only assign the first 2 as I really want to set these through Rails instead.

$ (event) ->
  app = angular.module "investor", []

  app.controller("InvestorCtrl", ["$scope", ($scope) ->
    $scope.houses = [
      { cost: "295000", value: "450000" },
      { cost: "600000", value: "620000"  }    
    ]
    $scope.calc_totals = ->
      # Initialise variables
      cost = 0
      value = 0

      # Go through each house and calculate the total cost
      for h in $scope.houses
        cost = parseInt(cost) + parseInt(h.cost)
        value = parseInt(value) + parseInt(h.value)

      # Set the total
      $scope.total_cost = cost
      $scope.total_value = value  

    # Run the calculation at the start  
    # $scope.calc_totals()
  ])

  angular.bootstrap document, ['investor']

Here is my form

%div{"ng-controller" => "InvestorCtrl"}
    = form_for(@investor) do |f|
        - if @investor.errors.any?
            #error_explanation
                %h2
                    = pluralize(@investor.errors.count, "error")
                    prohibited this investor from being saved:
                %ul
                    - @investor.errors.full_messages.each do |msg|
                        %li= msg
        .field
            = f.label :name
            = f.text_field :name, "ng-model" => "name"

        - i = 0
        = f.fields_for :houses do |builder|
            .field
                = render :partial => "house", :locals => {:f => builder, :i => i}
                - i = i + 1

        .field
            = f.label :total_cost
            = f.number_field :total_cost, "ng-model" => "total_cost"
        .field
            = f.label :total_value
            = f.number_field :total_value, "ng-model" => "total_value"
        .actions
            = f.submit

If I type in the first or second house ‘cost’ or ‘value’ then it updates the total_cost, but if I update the third house it will not update the total_cost.

Is there a way to dynamically tell angularjs to listen to these elements without assigning them in the controller?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:54:21+00:00Added an answer on June 13, 2026 at 6:54 am

    You’re actually going about this a little wrong, IMO. Since Angular can (and will) be handling the rendering of your repeating HTML for you, you don’t necessarily need to do your HTML rendering on the server. All you need from your server is some JSON. If you want it to be rendered right off the bat, you just make sure your initial values are set up properly when you initialize your controller.

    Inject $http or a custom made service into your controller, and pull the data you want directly from the server in JSON format, then plug it into your scope. If your HTML and directives are set up properly it will just render. From there all other logic will be the same.

    The web is moving forward. And by forward, I mean all of that HTML rendering stuff you used to do on the server is actually starting to be done on the client more and more. And that service layer you used to use to get your data on your web server? Well it is your web server now.

    I know this isn’t a direct answer to your problem, but it will greatly simplify what you’re trying to do. Otherwise you have a balancing act to perform that will get maddening pretty fast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.