Angularjs 如何在firebase和angularfire中使用ng repeat筛选出用户?
下面的代码使用ng repeat从firebase提取一个数组,并筛选用户ID 问题是,当我使用“!”时,它不会过滤掉用户,而是不会显示任何内容。换言之,当我更换以下ng重复过滤器时:Angularjs 如何在firebase和angularfire中使用ng repeat筛选出用户?,angularjs,filter,firebase,angularfire,ng-repeat,Angularjs,Filter,Firebase,Angularfire,Ng Repeat,下面的代码使用ng repeat从firebase提取一个数组,并筛选用户ID 问题是,当我使用“!”时,它不会过滤掉用户,而是不会显示任何内容。换言之,当我更换以下ng重复过滤器时: ng-repeat="(id,item) in ideas| filter:user.google.id" 有了这个ng repeat过滤器,为了过滤掉用户,它就不再工作了 ng-repeat="(id,item) in ideas| filter:user.google.id" 如何筛选出包含用户id的任何
ng-repeat="(id,item) in ideas| filter:user.google.id"
有了这个ng repeat过滤器,为了过滤掉用户,它就不再工作了
ng-repeat="(id,item) in ideas| filter:user.google.id"
如何筛选出包含用户id的任何项目的列表
有关完整代码,请参见下面和此代码笔中的内容:
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>
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();
}]);