angular-ui-router

AngularJS ui-router: Test ui-sref

别等时光非礼了梦想. 提交于 2019-12-08 23:55:20
问题 I'm trying to test some views, that are using <a ui-sref='someState'>link</a> to link to other states in my application. In my tests I'm triggering a click on this elements like this: element.find('a').click() How do I test, if the state is switched to someState ? It would be easy, when using $state in my controller like this: // in my view <a ng-click="goTo('someState')">link</a> // in my controller $scope.goTo = function(s) { $state.go(s) }; // in my tests spyOn($state, 'go'); element.find(

angularjs controller instantiation, ui-router

こ雲淡風輕ζ 提交于 2019-12-08 23:13:37
When do controllers get instantiated? Is it the first time you visit that state? also, What happens when you revisit the state, does a new controller get instantiated again? Assume that I have two states, A and B, and I put an alert statement at the top of state B. I noticed that if go from state A to B state B's alert statement sets off which tells me that the controller got instantiated. But suppose I go from state A to B to C and back to B, the alert statement does NOT go off. However, if I go from state A to B to C to B to A to B the alert statement goes off again. Here is a part of my

$stateParams converting value to string

末鹿安然 提交于 2019-12-08 22:03:18
问题 I am using UI-Router . Here's one of my state to which I am routing via ui-sref : .state("community", { url: "/community/:community_id", controller: "CommunityCtrl", templateUrl: "/static/templates/community.html" }) In one of my templates from where I go to 'community' state: <div ui-sref="community({community_id: community.community_id})"></div> Here's my community object: { name: 'Community name', community_id: 11 //int, not a string } As you can see the key 'community_id' contains an int

angular-ui-router 1.0.x: event.preventDefault & event.defaultPrevented alternative

荒凉一梦 提交于 2019-12-08 21:00:47
问题 I just replaced the $stateChangeStart with $transitions.onStart $rootScope.$on('$stateChangeStart', function(e, ...){ e.preventDefault(); // other code goes here... }); to $transitions.onStart({}, function(tras){ // need a code equivalent to e.preventDefault // need a code to identify event.defaultPrevented // other code goes here... // get parent states _o.util.getAncestorStates(toState.name, true).reverse() .forEach(function (state) { // certain condition to call event.preventDefault() if

Display parent state templates while child dependencies resolve

混江龙づ霸主 提交于 2019-12-08 19:39:51
问题 My app has nested states and views. Parent states are abstract and reference header templates. I would like to define resolve dependencies in the child states and have the header templates display while those dependencies load. Currently the parent state and child state wait for the child dependencies to resolve. Example code: angular.module("Test", ["ui.router"]) .config(function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise("/sec1"); $stateProvider.state("sec1", {

AngularJS : angular-ui-router always redirects to $urlRouterProvider.otherwise location

亡梦爱人 提交于 2019-12-08 17:43:42
问题 I'm trying to create an SPA where you have to be logged in to access almost everything. So naturally, the default screen you see is the login screen. However, after a user has logged in, no matter what the ui-sref is, ui-router redirects to the login page (even when the user is authenticated). Here is my ui-router code: (function () { 'use strict'; angular .module('app', ['ui.router', 'satellizer']) .config(function ($stateProvider, $urlRouterProvider, $authProvider, $httpProvider, $provide)

What is the difference between ui-view in angularjs and ion-nav-view in ionic

孤者浪人 提交于 2019-12-08 17:34:06
问题 As you know in angular ui-router we use ui-view to render an html to parent html . According to this: <!-- index.html --> <body> <div ui-view="filters"></div> <div ui-view="tabledata"></div> <div ui-view="graph"></div> </body> js file: $stateProvider .state('report', { views: { 'filters': { ... templates and/or controllers ... }, 'tabledata': {}, 'graph': {}, } }) Also in Ionic framework we can use this: <ion-nav-view name="filters"></ion-nav-view> What is the diference? 回答1: This is custom

Ui-sref not generating clickable links/not working

守給你的承諾、 提交于 2019-12-08 16:49:31
问题 I used ng-route for this before and it worked fine, but with UI Router, the links are not clickable anymore, or at least most of the time they aren't. When they are, which is very random, they don't display the html templates I'm using. HTML: <head> <title>Tutorial</title> <script src="lib/angular/angular.js"></script> <script src="lib/angular/angular-ui-router.min.js"></script> <script src="js/app.js"></script> <script src="js/controllers.js"></script> </head> <body> <ng-view></ng-view> <ul

ui.router: how to omit a default parameter from URL

我只是一个虾纸丫 提交于 2019-12-08 16:45:39
问题 I have the following states defined with $stateProvider: $stateProvider.state("byTeams", {url : "/team/{id}/{year}", ...}) $stateProvider.state("byPlayer", {url : "/player/{id}/{year}", ...}) When changing a year, I would like the URL to omit the {year} part of the URL if it matches the default (say 2014). In other words, when: $state.go("byTeams", {year: 2014}) --> www.example.com/app/#/team/343 $state.go("byTeams", {year: 2013}) --> www.example.com/app/#/team/343/2013 And when I switch to a

Cannot navigate same route in Angular

女生的网名这么多〃 提交于 2019-12-08 14:03:33
问题 I have a List and Details component in my Angular 7 project and I can open the details of a record by clicking the link on the List page. However, if I refresh on the same Details page or open the same Details page via hyperlink (e.g. opening the same record on the List in a new tab), HTTP Error 404.0 - Not Found is encountered. My code is as shown below: routing.module.ts: const routes: Routes = [ { path: 'user', component: UserPanelComponent children: [ { path: 'dashboard', component: