" UI-SREF"不刷新" UI-查看"当一个链接被点击两次(其控制器不重新运行) [英] "ui-sref" does not refresh the "ui-view"(its controller does not rerun) when a link is clicked twice

查看:149
本文介绍了" UI-SREF"不刷新" UI-查看"当一个链接被点击两次(其控制器不重新运行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当点击最初的状态,拥有了用户界面视图属性的div被替换成该国的模板。然而,当我再次点击相同的状态,它的控制器没有重新加载。我怎样才能让这个控制器再次加载?

When a state is clicked at first, the div that owns the "ui-view" attribute is replaced with the "template" of that state. However, when I click the same state again, its controller does not reloaded. How can I make this controller to load again?

例如,假设我有以下的导航菜单:

For example, suppose I have the following navigation menu:

<nav> 
    <a ui-sref="state1">State 1</a>
    <a ui-sref="state2">State 2</a>
</nav>

我的用户界面视图内容如下:

My "ui-view" content is as follows:

<div ui-view></div>

我的状态说明如下。当我点击导航菜单上的状态1,我希望能看到CTRL 1装的文本开发者控制台上。如果是第一次,我观察到的文字。然而,当我再次点击相同的链接,控制器不会重新加载这是我无法看到显示在控制台上两次CTRL 1装的文字。

My states are described as below. When I click the "State1" on the navigation menu, I expect to observe the text "Ctrl 1 loaded" on the developer console. If it's first time, then I observe that text. However, when I re-click the same link, the controller is not loaded again that is I couldn't see the text "Ctrl 1 loaded" displayed on the console twice.

myApp.config(function ($stateProvider, $urlRouterProvider){
    $stateProvider.state("state1", {
        url: "#",
        template: "<p>State 1</p>",
        controller: "Ctrl1"
      }).state("state2", {
        url: "#",
        template: "<p>State 2</p>",
        controller: "Ctrl2"
      });
});

为什么呢?你有什么想法?

Why? Do you have any idea?

下面是这个问题的的jsfiddle

推荐答案

像菲利普说,那是因为这是UI的路由器的默认行为,但如果你想每次都刷新你的控制器,你点击你的链接,你可以实际使用的 UI-SREF-OPTS 属性给力,就像这样:

Like Philipp said, it is because this is the default behavior of ui-router, BUT if you would like to reload your controller each time you click on your link, you can actually use the ui-sref-opts attribute to force it, like this:

<a ui-sref="state1" ui-sref-opts="{reload: true}">State 1</a>

找到这个技巧在这里:

Found this tip here:

<一个href=\"https://github.com/angular-ui/ui-router/commit/91a568454cc600aa4f34dedc8a80c9be1130b1c5\">https://github.com/angular-ui/ui-router/commit/91a568454cc600aa4f34dedc8a80c9be1130b1c5

希望它可以帮助

这篇关于&QUOT; UI-SREF&QUOT;不刷新&QUOT; UI-查看&QUOT;当一个链接被点击两次(其控制器不重新运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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