Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
Jquery 如何在数据更改时`$watch`并从`DOM'中删除类名`_Jquery_Html_Angularjs - Fatal编程技术网

Jquery 如何在数据更改时`$watch`并从`DOM'中删除类名`

Jquery 如何在数据更改时`$watch`并从`DOM'中删除类名`,jquery,html,angularjs,Jquery,Html,Angularjs,在我的场景中,我有活动标题。当用户点击其他字幕时,我在它之间交换数据 单击子标题时,我正在添加一个类名更新。当更新发生时,我需要在active指令中观察它,并且需要再次删除update类 如何做到这一点 我的HTML: <div class="wrapper" ng-app="myApp"> <div class="content" ng-controller="main"> <active-title></active-titl

在我的场景中,我有活动标题。当用户点击其他字幕时,我在它之间交换数据

单击
子标题
时,我正在添加一个类名
更新
。当更新发生时,我需要在
active
指令中观察它,并且需要再次删除
update

如何做到这一点

我的HTML:

<div class="wrapper" ng-app="myApp">
      <div class="content" ng-controller="main">
      <active-title></active-title>
      <sub-title  item='item' index=$index ng-repeat="item in items" change="changeItem"></sub-title>
    </div>
    </div>


由于您没有为指令创建作用域,并且在模型中有一个点,所以您可以直接从指令中查看它

scope.$watch('activeItem.name', function (newValue, oldValue) {
  console.log(newValue)
})
scope.$watch('activeItem.name', function (newValue, oldValue) {
  console.log(newValue)
})