开关相同的控制器内的景色,同时保留数据范围 [英] Switching views within the same controller whilst retaining scope data

查看:126
本文介绍了开关相同的控制器内的景色,同时保留数据范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可以被看作是一个列表或作为地图上的标记数据的一个页面。它还具有过滤在侧边栏。目前,我有这个结构为单独的地图和列表页面,但我想将它们合并,使过滤器保持切换视图时。

I have a page of data that can be viewed as a list or as markers on a map. It also has filtering in the sidebar. I currently have this structured as separate map and list pages but I want to merge them so that the filters remain when switching views.

我一直在使用 UI路由器而是试图由于我标记我不能让父母州内的过滤,根据我在这里的问题:<一href=\"http://stackoverflow.com/questions/33287030/how-do-i-show-multiple-views-in-an-abstract-state-template\">How做我展现在抽象状态模板多个视图?

I have tried using ui-router but due to my markup I cannot keep the filtering within a parent state, as per my question here: How do I show multiple views in an abstract state template?

我现在的标记是这样的:

My current markup is like this:

<div class="main-container" ng-controller="PlanningCtrl" data-county-parish-id="1478">
    <main class="page-content">
        <!-- toggles between map and list views -->
        <a href="/map">View map</a>

        <!-- main content view here -->
        <appl-list></appl-list>

        <!-- <appl-map></appl-map> -->
    </main>
    <aside class="sidebar">
        <div refine-results info="refine" id="SearchForm" class="refine-search"></div>
    </aside>
</div>

该数据阵列是控制器为 $ scope.filteredApplications 之内,这是过滤,并且每个指令内显示精细每一页上。

The data array is within the controller as $scope.filteredApplications and on each page this is filtering and displaying fine within each directive.

我想我的问题是:我怎么能在两个℃之间切换;申请 - *&GT; 指令和显示相同的过滤记录

I guess my question is: how can I toggle between the two <appl-*> directives and display the same filtered records?

推荐答案

您可以使用NG-如果你的指令,并根据一个范围的变量的设定值。

You can use ng-if with your directives and set value based on a scope variable.

您控制器会碰到这样的:

Your controller would have something like:

$scope.show = 'List'

然后,你有这个在您的HTML:

Then you'd have this in your HTML:

    <appl-list ng-if="show==='List'></appl-list>

    <appl-map ng-if="show==='Map'></appl-map>

然后你切换的列表之间scope.show $价值,并基于某些事件的地图。

Then you'd toggle the value of $scope.show between 'List' and 'Map' based on some event.

这篇关于开关相同的控制器内的景色,同时保留数据范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆