AngularJS Noob:如何从“调用控制器中的函数”;init";?

AngularJS Noob:如何从“调用控制器中的函数”;init";?,angularjs,Angularjs,我试图让事情保持干爽,所以我将重复代码移到控制器中的一个函数中,但它现在表示该函数未定义:Error:setFilterChoices未定义 app.controller('MensCtrl', ['$scope', "MensEyeglass", "MensSunglass", "Color", "Shape", "Material", function($scope, MensEyeglass, MensSunglass, Color, Shape, Material) { $scop

我试图让事情保持干爽,所以我将重复代码移到控制器中的一个函数中,但它现在表示该函数未定义:
Error:setFilterChoices未定义

app.controller('MensCtrl', ['$scope', "MensEyeglass", "MensSunglass", "Color", "Shape", "Material", function($scope, MensEyeglass, MensSunglass, Color, Shape, Material) {

  $scope.init = function(category) {
    $scope.colors = [];
    $scope.shapes = [];
    $scope.materials = [];

    switch (category) {
    case "Eyeglasses":
      $scope.products = MensEyeglass.query({}, setFilterChoices(data));
      break;
    case "Sunglasses":
      $scope.products = MensSunglass.query({}, setFilterChoices(data));
      break;
    }
  }


  //it's defined here isn't it??
  $scope.setFilterChoices = function(data) {
    for (var i = 0; i < data.length; i++) {
      var product = data[i];

      if ($scope.shapes.indexOf(product.shape) == -1) {
        $scope.shapes.push(product.shape);
      }

      if ($scope.materials.indexOf(product.material) == -1) {
        $scope.materials.push(product.material);
      }


      for (var j = 0; j < product.products_colors.length; j++) {
        var product_color =  product.products_colors[j];
        if ($scope.colors.indexOf(product_color.color) == -1) {
          $scope.colors.push(product_color.color);
        }
      }
    }
  }

当你调用它时,它在作用域上所以使用
$scope.setFilterChoices(数据)

当你调用它时,它在作用域上所以使用
$scope.setFilterChoices(数据)

当你调用它时,它在作用域上所以使用
$scope.setFilterChoices(数据)

它在作用域上所以使用
$scope.setFilterChoices(数据)
当你叫它的时候。

很好。谢谢如果不使用范围,我将如何操作?
var setFilterChoices=function(data){…}
,或
function setFilterChoices(data){…}
。那就按你原来说的那样称呼它吧。谢谢如果不使用范围,我将如何操作?
var setFilterChoices=function(data){…}
,或
function setFilterChoices(data){…}
。那就按你原来说的那样称呼它吧。谢谢如果不使用范围,我将如何操作?
var setFilterChoices=function(data){…}
,或
function setFilterChoices(data){…}
。那就按你原来说的那样称呼它吧。谢谢如果不使用范围,我将如何操作?
var setFilterChoices=function(data){…}
,或
function setFilterChoices(data){…}
。然后像你最初那样称呼它
  $scope.products = MensSunglass.query({}, function(data) {
    $scope.setFilterChoices(data);
  });