我是Firebase和Angular JS的新手,所以请原谅任何明显的"你到底做了什么" ...
我有几个嵌套的页面:
我的tab-specialty.html看起来像这样:
<ion-view view-title="{{specialty.name}}">
<ion-header-bar class="bar-positive bar-subheader item-input-inset">
<div class="button-bar">
...
</div>
</ion-header-bar>
<ion-content class="has-subheader">
...
</ion-content>
</ion-view>
这并不总是显示数据。我知道我在异步调用或其他方面做错了,因为看起来数据似乎并没有准备好了#39;供我展示。
{{specialty.name}}
并不总是显示。如果我在专业页面上ionic serve
,它将显示正常。但是,当我从较高级别开始并单击该页面时,它不会。
我的app.js中包含以下状态:
.state('tab.directory', {
url: '/directory',
views: {
'tab-directory': {
templateUrl: 'templates/tab-directory.html',
controller: 'DirectoryCtrl'
}
}
})
.state('tab.specialty', {
url: '/specialty/:specialtyId',
views: {
'tab-directory': {
templateUrl: 'templates/tab-specialty.html',
controller: 'SpecialtyCtrl'
}
}
})
.state('tab.team', {
url: '/team/:teamId',
views: {
'tab-directory': {
templateUrl: 'templates/tab-team.html',
controller: 'TeamCtrl'
}
}
})
我的controllers.js有以下专业控制器:
...
.controller('SpecialtyCtrl', function($scope, $stateParams, Specialties, Staff, Teams){
var specialtyId = $stateParams.specialtyId;
...
Specialties.$loaded().then(function(array){
var syncArray = array.getById(specialtyId);
if(syncArray.length > 0){
$scope.specialty = syncArray[0];
console.log($scope.specialty);
}
});
Staff.$loaded().then(function(array){
var allArray = array.getBySpecialtyId(specialtyId);
hasConsults = getHasConsults(allArray);
if(hasConsults){
// Default to consults if we have them
$scope.isConsultsActive = true;
$scope.staffList = allArray.filter(function(staff){
return staff.is_consult;
});
} else {
// If no consults, default to all
$scope.isAllActive = true;
$scope.staffList = allArray;
}
});
// Watch for new/updated/removed staff for this specialty
Staff.$watch(function(event){
var allArray = Staff.getBySpecialtyId(specialtyId);
hasConsults = getHasConsults(allArray);
// Sort the lists
allArray.sort(sortList);
$scope.allStaff = allArray;
if($scope.isConsultsActive){
$scope.staffList = allArray.filter(function(staff){
return staff.is_consult;
});
}
});
...
我的services.js定义了以下服务:
.service('Staff', function($firebaseArray, $window){
var staffList = $firebaseArray.$extend({
...
});
var ref = new $window.Firebase(FIREBASE_URL).child("staff");
var syncArray = new staffList(ref);
return syncArray;
})
.service('Teams', function($firebaseArray, $window){
var staffList = $firebaseArray.$extend({
...
});
var ref = new $window.Firebase(FIREBASE_URL).child("teams");
var syncArray = new staffList(ref);
return syncArray;
})
$ scope.specialty是一个似乎总是被填充的对象。我在团队页面上也遇到了同样的问题,但这个例子与此几乎完全相同。