单击导航栏后停止组件重新加载(Stop component reload after navbar is clicked)
我在Angular 2中有一个导航栏。它的工作原理如下。
<nav class="navbar navbar-toggleable-md navbar-light bg-faded"> <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="#">App</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav"> <li class="nav-item"> <a routerLink="/dashboard" routerLinkActive="active" class="nav-link">Home <span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a routerLink="/grid" routerLinkActive="active" class="nav-link" >Grid</a> </li> <li class="nav-item"> <a routerLink="/reporting" routerLinkActive="active" class="nav-link" >Reporting</a> </li> </ul> </div> </nav>
每个标签加载1个组件。 因此仪表板加载DashboardComponent和网格加载GridComponent。
上面提到的两个组件都从data.service.ts获取数据。 我的问题:有没有办法点击仪表板(它在3秒后加载),然后从仪表板选项卡导航到网格选项卡。 然后当我回到仪表板标签时,它是否可以重新加载并再次花费3秒钟?
我们在Angular 1.5中编写的应用程序没有上述问题。 问题是如果用户在仪表板和网格之间切换,则需要花费大量时间。
我看了下面提到的以下问题: 带有数据切换的Bootstrap选项卡会导致在angularjs中重新加载
他们都没有解决我的问题。 第一个问题是针对角度1.第二个问题,当我将导航项目设置为type =“button”时,重新加载仍在进行中。
I have a Navigation bar in Angular 2. It works like below.
<nav class="navbar navbar-toggleable-md navbar-light bg-faded"> <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="#">App</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav"> <li class="nav-item"> <a routerLink="/dashboard" routerLinkActive="active" class="nav-link">Home <span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a routerLink="/grid" routerLinkActive="active" class="nav-link" >Grid</a> </li> <li class="nav-item"> <a routerLink="/reporting" routerLinkActive="active" class="nav-link" >Reporting</a> </li> </ul> </div> </nav>
And each tab loads 1 component. So dashboard loads DashboardComponent and grid loads a GridComponent.
Both component mentioned above gets data from a data.service.ts. My question: is there a way to click on dashboard (it loads after 3 seconds), and then navigate away from dashboard tab to the grid tab. Then when I go back to the dashboard tab, can it not reload and take the 3 seconds time again??
The app we wrote in Angular 1.5 doesn't have the above problem. The issue is if the user is switching between dashboard and grid, it takes a lot of time.
I looked at the following questions asked here: Bootstrap's tabs with data-toggle cause reload in angularjs
Angular2 router.navigate refresh page
They both don't solve my problem. first question is for angular 1. and the second question, when I make my nav items into type="button", the reloading is still happening.
原文:https://stackoverflow.com/questions/44685050
最满意答案
相关问答
更多-
撬检查方法不起作用(pry inspect method not working)[2022-08-25]
Pry不只是使用inspect来显示返回值。 它调用一个名为print对象的proc,它在配置中定义。 在lib/pry.rb ,您可以发现它设置为: class Pry # The default print DEFAULT_PRINT = proc do |output, value, _pry_| _pry_.pager.open do |pager| pager.print _pry_.config.output_prefix Pry::ColorPrinte ... -
我认为你需要: require 'debugger/pry' 您可以将它添加到example.rb文件的顶部。 I think you need: require 'debugger/pry' you could add it to the top of your example.rb file.
-
首先在Gemfile中添加“pry-rails”gem gem 'pry-rails', :group => :development 然后bundle install 然后在沙箱模式下启动rails控制台 # in development env $ rails c --sandbox # or in test env $ rails c test --sandbox 就这样。 Pry将自动取代irb。 请享用! 参考: https : //github.com/pry/pry/wiki/Settin ...
-
节点文档 : 特殊变量_ (下划线)包含最后一个表达式的结果。 Node docs: The special variable _ (underscore) contains the result of the last expression.
-
Rails - IRB是否必要?(Rails — is IRB necessary?)[2022-03-02]
有关单独的脚本,请查看rails runner 。 它加载Rails后端,因此您可以访问所有模型并为此目的而存在。 来自“ Ruby on Rails指南 ”: runner以非交互方式在Rails的上下文中运行Ruby代码。 例如: $ rails runner“Model.long_running_method” For a separate script look into rails runner. It loads the Rails backend so you have access to a ... -
你如何安装pry插件?(How do you install pry plugins?)[2023-06-24]
每个以pry-开头的pry-插件都是自动加载的。 你只需要gem install pry-name 。 这是关于插件的链接(也创建插件)和确切的引用: 有效的Pry插件是具有pry-前缀的gem(例如pry-doc gem) 如果安装了Pry插件(即安装了pry-前缀的gem),它将在会话开始时自动加载。 注意: gem-install gem_name有特殊命令gem-install gem_name 。 您应该使用该命令而不是.gem install gem_name才能工作。 这个(pry)命令安装和 ... -
首先确保rvm正确加载: type rvm | head -n 1 # should be: rvm is a function type gem | head -n 1 # should be: gem is a function 如果它们不是函数,这意味着RVM没有正确加载,这可能是你的shell中的一个错误(比如限制bash),你可以尝试修复它: rvm get head --auto 可能需要在此命令后重新登录以运行所有shell配置文件。 接下来,请确保您使用rvm: rvm use 1.9. ...
-
您需要编辑主目录中的.editrc文件: nano ~/.editrc 并添加此行: bind "^R" em-inc-search-prev 资料来源: pry wiki You need to edit the .editrc file in your home directory: nano ~/.editrc And add this line: bind "^R" em-inc-search-prev Source: pry wiki
-
你可以使用bundle exec : bundle exec irb You can use bundle exec: bundle exec irb
-
使用_out_和_in_变量,如文档中所述。 例如: _out_[16]或_out_[-1]表示最后一个结果。 Using the _out_ and _in_ variables, as described in the docs. E.g.: _out_[16] or _out_[-1] for the last result.