admin管理员组文章数量:1401969
My Question is can we reload the view in ui-router if you are on same state. check my code at`
My app.js file is
var app = angular.module('plunker', ['ui.router']);
app.config(function($stateProvider) {
$stateProvider
.state("view1", {
url: "/view1",
templateUrl: "x.html"
})
.state("view2", {
url: "/view2",
templateUrl: "y.html"
})
})
app.controller("MainCtrl",function(){});
And index page is
<body ng-controller="MainCtrl">
<a href="#/view1">Accounts</a>
<a href="#/view2">Dashboard</a>
<div ui-view></div>
Now click on Dashboard link here you will see a text box. fill any value in that. Now again click on Dashboard link. now the state should reload and all data of page should be reloaded including its controller. Please make sure to ui-router only.
Thanks
My Question is can we reload the view in ui-router if you are on same state. check my code at`http://plnkr.co/edit/MA7CuyH2RFrlaoAgBYog?p=preview
My app.js file is
var app = angular.module('plunker', ['ui.router']);
app.config(function($stateProvider) {
$stateProvider
.state("view1", {
url: "/view1",
templateUrl: "x.html"
})
.state("view2", {
url: "/view2",
templateUrl: "y.html"
})
})
app.controller("MainCtrl",function(){});
And index page is
<body ng-controller="MainCtrl">
<a href="#/view1">Accounts</a>
<a href="#/view2">Dashboard</a>
<div ui-view></div>
Now click on Dashboard link here you will see a text box. fill any value in that. Now again click on Dashboard link. now the state should reload and all data of page should be reloaded including its controller. Please make sure to ui-router only.
Thanks
Share Improve this question asked Jul 4, 2014 at 18:35 Amit MouryaAmit Mourya 5381 gold badge7 silver badges19 bronze badges 2- Possible duplicate? stackoverflow./questions/21714655/… – Justin Obney Commented Jul 4, 2014 at 18:44
- Hi Justin here the question is different. I want to reload the page with menu click if same menu is clicked – Amit Mourya Commented Jul 5, 2014 at 5:01
4 Answers
Reset to default 7add attribute to the element with
ui-sref=""ui-sref-opts="{reload:true}"
example:
<a ui-sref-opts="{reload:true}" ui-sref="app.post.applicants">Applicants</a>
Use ng-click and write a controller function with $state.go
You could catch the click in a "ng-click" and use the $state service to transition/reload pragmatically
I had this similar issue and I solved this in two simple way ...
First I wrote a function into related controller (my state was 'inbox' you can use your own ui-state):
$scope.reload = function() { $state.go('inbox', null, { reload: true }); }
Second call this function to anchor tag:
<a ng-click="reload()">Inbox</a>
Hope it will help. :)
本文标签: javascriptreload state when you are on same state in angular uirouterStack Overflow
版权声明:本文标题:javascript - reload state when you are on same state in angular ui-router - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744230378a2596302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论