AngularJs位置路径没有改变所有控制器复位 [英] AngularJs location path change without all controllers resetting

查看:131
本文介绍了AngularJs位置路径没有改变所有控制器复位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

短版,我的问题是:我如何更改URL,而不需要触发路由变化或者没有必要运行当前显示的页面上的所有控制器

Short version of my question is: How do I change the URL without need to trigger route change or without need to run all the controllers on the currently displayed page?

详细内容:

我有一个在&LT内部显示的模板; NG-视图> 有3控制器管辖的区域。在页面的最顶端我有一个互动地图。当你点击的区域它广播点击其他组件上这个区域并显示数据回升。非常简单的设置。

I have a template which is displayed inside the <ng-view> that has regions governed by 3 controllers. On the very top of the page I have an interactive map. When you click on the regions it broadcasts a click and other component picks up on it and displays data about this region. Really simple setup.

我想要做的就是让我的用户深层链接的内容。所以每次有人点击一个链接时,我想改变可以被复制并粘贴到另一个浏览器的URL。其他一些用户可以只需点击链接,看到了同样的状态下,第一次看到了。

What I would like to do is allow my users to deep link to the content. So every time someone clicks on a link I'd like to change the URL that can be copied and pasted to another browser. Some other user could just click the link and see the same state the first one saw.

目前更改与code类似这样的位置:

Currently I change the location with code similar to this one:

  $scope.$on('mapRegionClick', function($scope, regionCode) {
    var url = generateURL(regionCode);

    $scope.currentScope.$apply(function(){
      $location.path(url);
    });});

该URL,然后在我的路由和地图加上数据显示拿起正确。这种方法的缺点是,每次我在地图上点击网址更改整个模板时间/视图再生。由于生成的地图是一种沉重的,我想只触发一个更改数据presenting控制器。

The URL is then picked up in my routing and the map plus data displays correctly. The downside of this is that every time I click on the map and URL changes the whole template / view is regenerated. Because generating the map is kind of heavy I'd like to trigger only a change to the data presenting controller.

这可能吗?怎么样?

我可以做控制器之间的一些通信,实现了我的目标,但我不能够做深层链接。

I could do some communication between controllers and achieve the my goal but then I would not be able to do deep linking.

PS:我不希望使用 $ location.search() reloadOnSearch = FALSE 。我的链接必须是pretty:)

PS: I do not want to use $location.search() and reloadOnSearch=false. my links have to be pretty :)

推荐答案

听起来像是你不希望使用的 $路线 服务。

Sounds like you don't want to use $route service.

$路线服务旨在重新加载控制器,以便有导航到一个URL并刷新URL之间没有差别。我们通过在每个URL变化做了充分的重装做到这一点。这是故意的。

The $route service is designed to reload the controllers so that there is no difference between navigating to a URL and refreshing the URL. We do this by doing a full reload on every URL change. This is intentional.

听起来像是你的使用情况,不应该用 $路线,只的 $位置 和的 NG-包括

Sounds like your use case, should not be using $route, just $location and ng-include.

这篇关于AngularJs位置路径没有改变所有控制器复位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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