【发布时间】:2017-06-20 13:56:34
【问题描述】:
您好,我正在使用 Firebase 和 AngularJS 构建应用程序。 我有两个父母,一个包含游戏中的每个怪物,另一个包含用户拥有的每个怪物。
我需要一个中继器来消除用户怪物,并显示其他所有内容。我尝试了很多方法,我觉得使用指令我非常接近逻辑。
index.html:
<div ng-repeat="monster in monsters" my-directive="monster">
<h2>{{monster.name}}</h2>
</div>
services.js
.directive('myDirective', function(Auth, $firebaseArray){
rdef =''
Auth.$onAuth(function(authData) {
var username = authData.uid;
var ref = new Firebase("firebaseurl");
var hopref = ref.child(username);
var results = $firebaseArray(hopref);
results.$loaded(function(x) {
angular.forEach(results, function(value, key){
if(myDirective.name == value.Monster){
rdef ='<div></div>'
}else{
rdef ='<div>{{ myDirective.name }}</div>'
}
});
});
});
return {
restrict: "A",
template: rdef ,
scope: {
myDirective: '='
},
link: function(scope, element, attrs) {
console.log('MyData', scope.myDirective);
}
};
});
我对 Angular 还是很陌生,任何帮助都将不胜感激。 (我也是 Stackoverflow 的新手,所以如果我做错了什么,请告诉我)
谢谢!!!
【问题讨论】:
标签: angularjs loops firebase ng-repeat directive