Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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
Angularjs 指令的角度过滤器内容_Angularjs - Fatal编程技术网

Angularjs 指令的角度过滤器内容

Angularjs 指令的角度过滤器内容,angularjs,Angularjs,我希望能够通过我的数据JSON中的“cat”:属性过滤自定义元素ng repeat的内容。我有角度指令的基本经验,但正如你所说,我的理解还远远不够熟练。我有一种感觉,问题在于我对scope{}和cat属性的指令,但我对如何继续有点困惑。目前我的HTML是这样的: HTML: JSON来自JS文件: $scope.businesses = [ {"name": "Obi-Wan Kenobi", "index":88, "cat": "jedi"}, {"na

我希望能够通过我的数据JSON中的
“cat”:
属性过滤自定义元素ng repeat的内容。我有角度指令的基本经验,但正如你所说,我的理解还远远不够熟练。我有一种感觉,问题在于我对scope{}和cat属性的指令,但我对如何继续有点困惑。目前我的HTML是这样的:

HTML:

JSON来自JS文件:

$scope.businesses = [
    {"name": "Obi-Wan Kenobi",
     "index":88,
      "cat": "jedi"},
    {"name": "Yoda",
     "index":69,
      "cat":"jedi"},
    {"name": "Lando",
     "index":31,
      "cat": "smuggler"},
    {"name": "Han Solo",
     "index":90,
      "cat": "smuggler"},
    {"name": "Darth Vader",
     "index":98,
      "cat": "sith"},
    {"name": "Jar-Jar Binks",
     "index":80,
      "cat": "alien"},
    {"name": "Mace Windu",
     "index":45,
      "cat": "jedi"},
    {"name": "Chewy",
     "index":76,
      "cat": "smuggler"}
  ];

在指令模板中,尝试使用过滤数组:

   <li data-ng-repeat="character in cat">
        <h2>{{character.name}}</h2>
   </li>
  • {{character.name}
  • .directive('filteredRepeat', function() {
      return {
        restrict: 'E',
        scope: {
          cat: '='
    },
        templateUrl: 'partials/filtered-repeat.html'
      };
    });
    
    $scope.businesses = [
        {"name": "Obi-Wan Kenobi",
         "index":88,
          "cat": "jedi"},
        {"name": "Yoda",
         "index":69,
          "cat":"jedi"},
        {"name": "Lando",
         "index":31,
          "cat": "smuggler"},
        {"name": "Han Solo",
         "index":90,
          "cat": "smuggler"},
        {"name": "Darth Vader",
         "index":98,
          "cat": "sith"},
        {"name": "Jar-Jar Binks",
         "index":80,
          "cat": "alien"},
        {"name": "Mace Windu",
         "index":45,
          "cat": "jedi"},
        {"name": "Chewy",
         "index":76,
          "cat": "smuggler"}
      ];
    
       <li data-ng-repeat="character in cat">
            <h2>{{character.name}}</h2>
       </li>