How to filter out a user using ng-repeat within fi

2019-08-20 04:36发布

问题:

The below code pulls an array from firebase using ng-repeat and filters for the userId.

The issue is that when I use "!" it does not filter out the user, but instead nothing shows up. In other words when I replace the below ng-repeat filter:

ng-repeat="(id,item) in ideas| filter:user.google.id"

with this ng-repeat filter, with the intention of filtering out the user, it no longer works.

ng-repeat="(id,item) in ideas| filter:user.google.id"

How can I filter out list for any item that contains the user id?

See below and in this codepen for the full code: http://codepen.io/chriscruz/pen/LERrBW

HTML

<html ng-app="app">
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
        <script src="https://cdn.firebase.com/js/client/2.0.2/firebase.js"></script>
        <script src="https://cdn.firebase.com/libs/angularfire/0.9.0/angularfire.min.js"></script>
        <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    </head>
<body ng-controller="ctrl">
  <p>Welcome, {{user.google.displayName}}</p>
  <button class="btn btn-lg btn-danger" id="Gbtn" ng-click="GoogleLogin()">
    <i class="fa fa-google-plus-square fa-2x"></i>
    Login with Google</button>
  <table>
  <tr class="item" ng-repeat="(id,item) in ideas| filter:user.google.id">
    <td>{{item.idea}}</td>
  </tr>
  </table>


</body>
</html>

Javascript:

var app = angular.module("app", ["firebase"]);

app.constant("FBURL", "https://crowdfluttr.firebaseio.com/");

app.service("Ref", ["FBURL", Firebase]);

app.factory("Auth", ["$firebaseAuth", "Ref", function($firebaseAuth, Ref) {
  return $firebaseAuth(Ref);
}]);

app.factory("Ideas", ["$firebase", "Ref", function($firebase, Ref) {
  var childRef = Ref.child('ideas');
  var lst = $firebase(childRef).$asArray();
  return lst
}]);


app.controller("ctrl", ["$scope","$firebase","Ideas","Auth", function($scope,$firebase,Ideas,Auth) {
  $scope.ideas = Ideas;
  $scope.auth = Auth;
  $scope.idea = "";

  $scope.GoogleLogin = function () {   
    $scope.auth.$authWithOAuthPopup('google')()
  };


}]);

app.run(["$rootScope", "Auth", function($rootScope, Auth) {
  $rootScope.user = Auth.$getAuth();
}]);