私は、1つのビデオだけを持つものと同様に、私がフィルター、記事、最新の記事、 trueにクリックされたボタンの箇条書きを設定し、次のようにクリックされたボタン私がチェックし、コントローラで角度 - どのステートメントが真であるかチェックし、そのステートメントに基づいて変数を作成する
<a class="button button-icon" href="#" ng-click="articleFilter('siste')"><i class="ion-ios-circle-filled" ng-show="bulletpointSiste"></i> Siste
</a>
<a class="button button-icon" href="#" ng-click="articleFilter('video')"><i class="ion-ios-circle-filled" ng-show="bulletpointVideo"></i> Video
</a>
<a class="button button-icon" href="#" ng-click="articleFilter()"><i class="ion-ios-circle-filled" ng-show="bulletpointPopular"></i> Populært
</a>
、その後でビューを更新します。また、私はまた、アクティブなボタンに箇条書きを追加してい追加してい関数を呼び出すdoRefresh
:
$scope.articleFilter = function(button) {
if (button == "siste"){
$scope.bulletpointSiste = true;
$scope.bulletpointPopular = false;
$scope.bulletpointVideo = false;
$scope.articleType = 'all';
}
else if (button == "video"){
$scope.bulletpointSiste = false;
$scope.bulletpointPopular = false;
$scope.bulletpointVideo = true;
$scope.articleType = 'video';
}
else {
$scope.bulletpointVideo = false;
$scope.bulletpointSiste = false;
$scope.bulletpointPopular = true;
$scope.articleType = 'popular';
}
$scope.doRefresh();
}
ファンクションdoRefresh
は、どの箇条書きが真であるかをチェックし、正しいサービスタイプを呼び出すために、正しいフィルタタイプにvar articleType
を設定します。今私はこれに別のフィルタを追加する必要があるので、私はロジックを変更する必要があります。私はこれを行うための最もエレガントな方法は何かわからない、私はarticleFilter
関数に別のelse if
のステートメントを追加することができます:私は疑問に思って
$scope.doRefresh = function(){
var articleType = $scope.articleType ? $scope.articleType : 'all';
ArticleService[articleType]().$promise.then(function(data){
$scope.articles = data;
}).finally(function() {
$scope.$broadcast('scroll.refreshComplete');
});
};
を正しいbullet point
true
に設定するいくつかのよりエレガントな方法がある場合:
$scope.articleFilter = function(button) {
$scope.bulletPoint = button;
// articleType should be all when 'siste', so a bit different...
if(button == 'siste') $scope.articleType = 'all';
else $scope.articleType = button;
}
そして、あなた:
if (button == "siste"){
$scope.bulletpointSiste = true;
$scope.bulletpointPopular = false;
$scope.bulletpointVideo = false;
$scope.articleType = 'all';
}
else if (button == "video"){
$scope.bulletpointSiste = false;
$scope.bulletpointPopular = false;
$scope.bulletpointVideo = true;
$scope.articleType = 'video';
}
else {
$scope.bulletpointVideo = false;
$scope.bulletpointSiste = false;
$scope.bulletpointPopular = true;
$scope.articleType = 'popular';
}