gpt4 book ai didi

javascript - 无法绑定(bind)数据查看angularjs

转载 作者:行者123 更新时间:2023-11-30 16:24:06 25 4
gpt4 key购买 nike

我在使用 ionic 框架中的 angularjs 将我的数据绑定(bind)到我的 View 时遇到了一些问题。

这是我的 controller.js:

.controller('InventoryCtrl', function($scope, Category, Inventory) {
$scope.categories = Category;


$scope.searchInventory = function(category){
var word = category.Category;

var ref = new Firebase('https://vivid-heat-2430.firebaseio.com/');

var invenRef = ref.child('Inventories');
var prodRef = invenRef.child('Products');


invenRef.orderByChild("Products").on("child_added", function(snapshot) {
var data = snapshot.val();
var store = data.Inventory;
var prod = data.Products;
var test = Object.keys(prod);

for( var i = 0; i < test.length; i++){
if (test[i] == word) {
console.log(test[i]);
console.log("Storage place: " + data.Inventory + " Datum inventaris: " + data.Date);
$scope.show= test[i];

};

};

});

};
})

在这里,我正在从我的数组中获取我的产品。那我比较一下。它会给我匹配的对象,还会给我它所属的存储位置。我可以将其记录在我的控制台中。但是当我试图将它绑定(bind)到我的 View 时。它什么也没给我。

这是我的 index.html:

<ion-content>
<p><b>Zoek categorie</b></p>
<ion-scroll direction="y" >
<div style="max-height: 300px" ng-controller="InventoryCtrl">
<ion-list>
<ion-radio ng-repeat="category in categories" class="item-accordion" ng-model="checked.check" value="{{category.Category}}" ng-click="searchInventory(category)">
<p>{{category.Category}}</p>
</ion-radio>
<br>
</ion-list>
</div>

<div>
<ion-list>
<ion-item>
{{show}}
</ion-item>
</ion-list>
</div>
</ion-scroll>
</ion-content>

我不明白我做错了什么……是因为我的$scope.show还在.on方法里面吗?

最佳答案

不太熟悉 Firebase,但我假设它是您用来提取数据的第 3 方服务。您的数据更新可能发生在 Angular 摘要周期之外。将数据附加到范围后,只需添加它即可。

$scope.digest()

关于javascript - 无法绑定(bind)数据查看angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34358295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com