【问题标题】:Where can I put the $scope into the controller in that way? [closed]我可以在哪里以这种方式将 $scope 放入控制器中? [关闭]
【发布时间】:2014-02-07 00:39:41
【问题描述】:

如果我将 $scope 放在控制器中,我应该把它放在哪里?

angular.module('FilterInControllerModule', []).
      controller('FilterController', ['filterFilter', function(filterFilter) {
        this.array = [
          {name: 'Tobias'},
          {name: 'Jeff'},
          {name: 'Brian'},
          {name: 'Igor'},
          {name: 'James'},
          {name: 'Brad'}
        ];
        this.filteredArray = filterFilter(this.array, 'a');
      }]);

【问题讨论】:

  • controller('FilterController', ['filterFilter', '$scope', function(filterFilter , $scope) {

标签: angularjs filter controller


【解决方案1】:

在数组中作为控制器方法的第二个参数。但是您不需要指定整个数组。您可以将其作为控制器函数的参数传递。

controller('FilterController', function(filterFilter, $scope) {
    this.array = [
      {name: 'Tobias'},
      {name: 'Jeff'},
      {name: 'Brian'},
      {name: 'Igor'},
      {name: 'James'},
      {name: 'Brad'}
    ];
    this.filteredArray = filterFilter(this.array, 'a');
  });

【讨论】:

  • 我认为使用 $scope.array =[your data];和 $scope.filteredArray = filterFilter(this.array, 'a');是更清洁的方式。
  • @DilipKumar 它不像你写的那样工作
猜你喜欢
  • 1970-01-01
  • 2013-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-22
相关资源
最近更新 更多