AngularJs Watch(childscope)呼叫成员功能

时间:2015-03-18 18:23:35

标签: angularjs

我的指令在ng-if中,因此它创建了自己的子范围。如果我在watch函数中调用console.log $ scope它似乎是父元素。但是在Angular中,您无法从父级访问childscope。如果我删除HTML中的$ parent,则watch函数不再起作用。该指令无法使用ng-change。如何查看是否发生了更改,然后调用filterWithOptions函数。

JS

angular.module("blub").controller('TagCtrl', function($scope, $rootScope, filterService, optionsService) {
  var self;
  self = this;
  $scope.min = 0;
  $scope.max = 10;
  this.filterOptions = function() {
    return optionsService.getToggleStatus('erweiterteSuchoptionen');
  };
  this.filterWithOptions = function(self) {
    console.log("Filter with options", $scope.min, $scope.max);
    filterService.setMinMax($scope.min, $scope.max);
    return self.filter();
  };
  this.filter = function() {
    console.log("Filter");
    filterService.setIncludeTags($scope.tagsInclude);
    filterService.setExcludeTags($scope.tagsExclude);
    $scope.filtered = filterService.filter();
    $scope.number = $scope.filtered.length;
    $rootScope.$broadcast('FILTERED');
  };
  $scope.$watch('min', function() {
    return console.log($scope);//works
  });
  //$scope.$watch('min', ???); //What to put in here
});

HTML

<div ng-if="tagController.filterOptions()" class="filter-options">
   <h2>Anzahl(Minimal - Maximal)</h2>
   <div range-slider min="0" max="10" model-min="$parent.min" model-max="$parent.max"  show-values="true"></div>
</div>

0 个答案:

没有答案