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 9111817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:35:30+00:00 2026-06-17T03:35:30+00:00

I have the following Rails HAML: = select_tag some-class, options_for_select([[‘None’, ”]], ”), { class:

  • 0

I have the following
Rails HAML:

 = select_tag "some-class",
                        options_for_select([['None', '']], ''),
                        { class: 'some-other-class',
                          'ng-model' => 'someModel',
                          'ng-options' => 'option.name for option in someList',
                          'ng-change' => 'updateSelected()'}

Angular Controller:

  scope.updateSelected = ->
       #logic for updating model lives here. Model updates successfully by using some values defined within scope. Includes the following:
       scope.someModel = "some_new_value"

Angular Directive:

  SomeClassDirective= ->
       restrict: 'C'

       link: (scope, element, attrs) ->

            monitorFormFields = (newValue, oldValue) ->
                   console.log "this is the inner function call"
                   #logic for setting the inner _destroy field lives here

            scope.$watch 'someModel', monitorFormFields

However, when the Select List value is changed, ‘this is the inner function call’ never prints.(it does print when the directive first initializes, ie at page load). My question therefore is: Why isn’t the $watch expression triggering, and how do I get it to trigger?

Thanks!

  • 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-17T03:35:32+00:00Added an answer on June 17, 2026 at 3:35 am

    With this HTML:

    <select class="some-class" ng-model="someModel" 
       ng-options="option.name for option in someList"></select>
    

    Here is a directive that will watch for a change to someModel:

    myApp.directive('someClass', function () {
      return {
        restrict: 'C',
        link: function (scope, element, attrs) {
          var monitorFormFields = function (newValue, oldValue) {
            console.log("this is in the inner function call");
          }
          scope.$watch('someModel', monitorFormFields);
        }
      }
    });
    

    Controller:

    $scope.someList = [{ name: 'name1' }, { name: 'name2' }];
    

    Note that you don’t need to call a controller method to update someModel — Angular does that automatically for us because of the ng-model attribute. So, the directive only needs to $watch for a change to that $scope property.

    Fiddle.


    I would like to from the element fetch a sibling with [_destroy] in the name and set it to either “0” or “1” depending on the value of the select box.

    A more Angular approach would be to have model properties control whether “0” or “1” is displayed. E.g., in your controller:

    $scope.destroy1 = "0";
    $scope.destroy2 = "0";
    

    In your HTML:

    <div>{{destroy1}}</div>
    <div>{{destroy2}}</div>
    

    In monitorFormFields() you can change the values of these scope properties, and the view will automatically update — there is no need to “find” siblings or update .val()ues.

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

Sidebar

Related Questions

i have the following code in the rails company model: class Company include Mongoid::Document
I have a the following rails models: class Release < ActiveRecord::Base has_many :release_questionnaires, :dependent
I am using Rails 3.2. I have following models: Blog Comment User class Blog
This is a Rails 3 application with HAML. I have the following: = f.fields_for
I'm running Rails 3.1.1, RSpec 2.7.0 and HAML 3.1.3. Say I have the following
I have the following haml code: %input{:value => , :type => button,:class => SendBtn,
I have the following Rails migration: class AddTextToReference < ActiveRecord::Migration def change add_column :references,
I have the following rails code in a loop that has a link for
In my rails view(index.html.erb), i have following structure <div> <%= render :partial => create
I have the following code in my Rails application's routes file: MyApp::Application.routes.draw do constraints

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.