我是角色新手,有一个应用程序从firebase实例中提取数据。如何将firebase连接放在Angular服务中,并将返回的数据传递给users
指令? firebase数据当前正在呈现给标记中的users-directive
,但它不是通过指令本身完成的。如何将其正确传递给指令以使其仅显示名称?
控制器
var myApp = angular.module('myApp', ['firebase']);
myApp.controller('ChatCtrl', ['$scope', '$firebaseArray', function($scope, $firebaseArray){
var myUsers = new Firebase('https://db.firebaseio.com/users');
console.log(myUsers)
$scope.users = $firebaseArray(myUsers);
$scope.showUsers = function(users){
$scope.users = users.name;
$scope.users = users.userId;
}
}]);
chatApp.directive("showUsers", function(){
return {
restrict: 'E',
scope: {
user: '@'
},
templateUrl: "usersList.tpl.html"
};
});
用户列表模板
<p>Users</p>
<ol class="list-unstyled animated fadeInDown" ng-repeat="user in users">
<li><a href="#" id="{{user.userId}}">{{user.name}}</a></li>
</ol>
JSBIN :LINK