问题描述
如何从ng-repeat记录/访问对象数据? 当我单击其li元素时,我希望能够访问每个特定的firebase对象。 我已经能够记录整个对象,但是我只需要针对该特定li的数据?
pomodoro_timer.controller('timer', ['$scope','$interval','$firebaseArray', function ($scope, $interval, $firebaseArray) {
var ref = new Firebase("https://pomodoro-timer7710.firebaseIO.com/");
$scope.working = $firebaseArray(ref)
$scope.addWork = function() {
if ($scope.newWork == null) {
WorkInputField.placeholder = "Please enter a job"
}
$scope.working.$add({
name: $scope.newWork,
startedAt: Date.now(),
completed: false
});
$scope.newWork = "";
}
$scope.showTime = function() {
ref.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
}
的HTML
<div id="workInfo">
<div id="enterWork">
<form ng-submit="addWork()">
<input id="WorkInputField" type="text" placeholder="Job to complete" ng-model="newWork"></input>
</form>
<h3>Your Work:</h3>
<ul>
<li class="workList" ng-repeat="work in working" ng-click="showTime()">
{{ work.name }}
<a href="#" ng-click="working.$remove(work)"><span class="removeWork">Done</span></a>
</li>
</ul>
</div>
</div>
我希望这是足够的代码,所有与问题有关的代码。 当我单击每个单独的li时,我想查看其键/值对。 谢谢,我想把我的头缠在Angular上,这使我发疯。
1楼
Huy Hoang Pham
1
已采纳
2015-07-31 01:40:28
HTML:
<li class="workList" ng-repeat="work in working" ng-click="showTime(work)"> ...</li>
控制器:
$scope.showTime = function(work) { console.log(work); }
只需阅读ng-repeat的有角度的文档,您就会了解它的工作原理。