Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 监视表达式未从ng更改中获取模型更改_Ruby On Rails_Coffeescript_Angularjs_Haml - Fatal编程技术网

Ruby on rails 监视表达式未从ng更改中获取模型更改

Ruby on rails 监视表达式未从ng更改中获取模型更改,ruby-on-rails,coffeescript,angularjs,haml,Ruby On Rails,Coffeescript,Angularjs,Haml,我有以下几点 铁路HAML: = select_tag "some-class", options_for_select([['None', '']], ''), { class: 'some-other-class', 'ng-model' => 'someModel', 'ng-opti

我有以下几点 铁路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()'}
角度控制器:

  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"
$scope.someList = [{ name: 'name1' }, { name: 'name2' }];
$scope.destroy1 = "0";
$scope.destroy2 = "0";
角度指令:

  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
但是,当更改Select List值时,“this is the internal function call”(这是内部函数调用)不会打印。它会在指令首次初始化时打印,即在页面加载时打印。因此,我的问题是:$watch表达式为什么不触发,以及如何触发它

谢谢

使用此HTML:

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

  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"
$scope.someList = [{ name: 'name1' }, { name: 'name2' }];
$scope.destroy1 = "0";
$scope.destroy2 = "0";
请注意,您不需要调用控制器方法来更新someModel-Angular会自动为我们这样做,因为ng model属性。因此,指令只需要$watch就可以更改$scope属性


我想从元素中获取名称中带有[\u destroy]的同级,并根据选择框的值将其设置为0或1

更具角度的方法是让模型属性控制显示0还是1。例如,在控制器中:

  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"
$scope.someList = [{ name: 'name1' }, { name: 'name2' }];
$scope.destroy1 = "0";
$scope.destroy2 = "0";
在HTML中:

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

在monitorFormFields中,您可以更改这些作用域属性的值,视图将自动更新-无需查找同级或更新。值。

ng单击支持$event,但是ng的变化似乎没有。有没有关于如何绕过这个限制的建议?也许有一种方法可以在没有事件的情况下做你想做的事情。你想对该事件做什么?我想从元素中获取一个名为[_destroy]的兄弟,并根据select BOX的值将其设置为0或1。你可以$scope。$watch someModel,function{}在选择更改时触发一个处理程序。谢谢!相关信息是,ng更改是不必要的!事实上,改变打破了我的逻辑,不知道为什么,也不完全确定我是否在乎。至于破坏,我很感兴趣,将去重写它。非常感谢。