Angularjs: $filter in controller

后端 未结 1 1511
面向向阳花
面向向阳花 2021-02-05 09:10

Having issues with getting this filter to work.

$scope.imgCollection.then(function (images) {
    $scope.images = images.thisGal_images;

    if ($scope.images[0         


        
1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 09:46

    I created a demo for you and hopefully you can compare the code and figure out the issue.

    I guess you might forget to inject $filter module. Please take a look a the demo.

    {{image}}
    var app = angular.module('myApp', []); function ctrl($scope, $filter) { $scope.images = [{ orgName: 'B', sortOrder: 111 }, { orgName: 'A', sortOrder: 12 }, { orgName: 'D', sortOrder: 13 }, { orgName: 'C', sortOrder: 14 }]; $scope.order = function (order) { if (order == '0') { $scope.images = $filter('orderBy')($scope.images, 'orgName'); } else { $scope.images = $filter('orderBy')($scope.images, 'sortOrder'); } } }

    Working Demo

    0 讨论(0)
提交回复
热议问题