我试图使用URL将信息从我的列表传递到详细信息视图。我的网址包含Firebase ID。我设法找回了ID,但是我找不到如何在Firebase中读取相应的记录。
我有一个瓶子的列表,当我点击一个瓶子时,我想显示它的名字。
bouteilles.js
angular.module('myApp.bouteilles', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/bouteilles', {
templateUrl: 'bouteilles/bouteilles.html',
controller: 'BouteillesCtrl'
});
}])
.controller('BouteillesCtrl', ['$scope','$firebaseArray', function($scope, $firebaseArray) {
var ref = firebase.database().ref();
$scope.bouteilles = $firebaseArray(ref);
}]);
然后,我有 “BOUTEILLES” 的列表: bouteilles.html
<div class = "list" ng-repeat="bouteille in bouteilles>
<a class="item item-avatar" href="#!/maBouteille/{{bouteille.$id}}">
<h2>{{bouteille.name}} - {{bouteille.year}}</h2>
</a>
</div>
所以,我在URL中的瓶ID。它工作正常,因为我可以在日志中从maBouteille.js
angular.module('myApp.maBouteille', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/maBouteille/:id', {
templateUrl: 'maBouteille/maBouteille.html',
controller: 'MaBouteilleCtrl'
});
}])
.controller('MaBouteilleCtrl', ['$routeParams','$scope','$firebaseArray', function($routeParams, $scope, $firebaseArray) {
var ref = firebase.database().ref();
console.log($routeParams.id);
}]);
看到ID我想不通我怎么可以用这个$ routeParams.id检索火力地堡中的相应记录。任何想法?
你会得到完整的对象在bouteille对象ng重复。为什么你想要获取@fabien –
在MaBouteilleCtrl中,我想从点击瓶中找到数据 –
什么是你的节点名? –