我只是在项目中学习firebase和anfularfire。
var myApp = angular.module('myApp', ['ngRoute','firebase']);
myApp.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "home.html",
controller: "TodoCtrl"
})
.when("/$id", {
templateUrl: "single.html",
controller: "SinglePage"
})
});
myApp.controller('TodoCtrl', function TodoCtrl($scope, $location, $firebase) {
var fireRef = new Firebase('https://burning-heat-LINK.firebaseio.com/users');
$scope.todos = $firebase(fireRef).$asArray();
$scope.newTodo = '';
$scope.addTodo = function() {
var newTodo = $scope.newTodo;
if (!newTodo.length) {
return
}
$scope.todos.$add({
title: newTodo
})
$scope.newTodo = ''
};
$scope.removeTodo = function(todo){
$scope.todos.$remove(todo);
};
$scope.doneEditing = function(todo){
var title = todo.title;
if (title) {
$scope.todos.$save(todo);
} else {
$scope.removeTodo(todo);
}
};
});
我有问题如何获取单个用户页面的数据。当我点击链接下面的链接时,我不会去数据只是单个用户的页面。
<a ng-href="/#/{{todo.$id}}">{{todo.$id}}</a>
myApp.controller('SinglePage', function SinglePage($scope, $location, $firebase) {
var singlePageFirebase = new Firebase('https://burning-heat-LINK.firebaseio.com/').child('users');
$scope.singlePage = $firebase(singlePageFirebase);
console.log("singlePage", $scope.singlePage);
});