以下是我正在嘗試執行的操作。我正在使用離子,角度來構建應用程序,並且我有兩個選項卡,列出了用戶輸入的問題列表。一旦在第一個選項卡(選項卡a)上回答了一個問題,它會使用ng隱藏 - 如果因爲屬性被添加稱爲「對話」,所以問題從一個選項卡移動到另一個選項卡,通過它隱藏在另一個選項卡中並顯示在另一個選項卡中。這一切工作正常。在ng-if後面添加消息如果刪除所有元素
但是,一旦沒有問題了,因爲它們全都隱藏在標籤a中,我想顯示一條消息。這是最累人的試驗,我曾經犯過一個錯誤(主要是錯誤)。我有不同的指令配置,最近還有一個自定義過濾器,沒有任何東西可以完美工作。
下面是一些實驗代碼。我試着在選項卡上聽。 (這只是一個嘗試。我也嘗試過自定義過濾器和該指令的另一配置)
//template
<ion-view view-title="Questions">
<ion-content>
<ion-list ng-show="rooms" class="display-text">
<ion-item class="item-icon-left questions" ng-repeat="room in rooms" ng-if="!room.conversation" type="item-text-wrap" ng-click="openChatRoom(room.schoolid, room.$id, room.userid, room.question)">
<i class="icon {{room.icon}}"></i>
<h2>{{room.question}}</h2>
</ion-item>
</ion-list>
<div class="msg"></div>
<ion-list ng-hide="rooms.length">
<ion-item class="textCenter">
<i class="icon ion-loading-c"></i> Loading Rooms
</ion-item>
</ion-list>
</ion-content>
restrict: 'C',
link: function(scope, elem, attrs) {
scope.$watch('tabs', function(){
var myEl = angular.element(document.querySelector('.questions'));
if(scope.tabs == 'ctrl1'){
if(!myEl){
var temp = $compile('<ion-item class="textCenter"><i>No conversations<i></ion-item>');
var content = temp(scope);
elem.find('div').append(content);
}
}
if(scope.tabs == 'ctrl2'){
if(!myEl){
var temp = $compile('<ion-item class="textCenter"><i>No current questions<i></ion-item>');
var content = temp(scope);
elem.find('div').append(content);
}
}
});
爲什麼不使用UI的路由器,併成立了多頁的形式,類似於https://開頭威士忌.IO /教程/ angularjs-多步驟外形使用-UI-路由器?使用'elm.find'指令是jQuery風格的做事方式。 – Claies