angular-routing

$rootScope.$on(“$routeChangeSuccess) or $rootScope.$on(”$stateChangeSuccess) does not work when using ui-router(AngularJS)

我只是一个虾纸丫 提交于 2019-12-12 10:37:26
问题 I am using UI-router for nested views in my application but at the sametime I want to listen for events when the route changes. Before using UI-router routeChangeSuccess was firing just fine but after ui-router it does not fire. Documentation suggests to use viewContedLoaded or stateChangeSuccess to be used but even they dont get fired. I am pasting my code snippet. Any help would be appreciated. var app = angular.module('SmartKart', ['ngCookies','ngRoute','ui.bootstrap','angularPayments',

Angular 5 - Dynamic Route Added but not routing

我的梦境 提交于 2019-12-12 09:23:57
问题 I have created a new project and added some code to to the routing module for dynamic routing: Here is the routing module code: import { NgModule } from '@angular/core'; import { Routes, RouterModule, Router} from '@angular/router'; import { OneComponent } from './one/one.component'; import { HomeComponent } from './home/home.component'; const routes: Routes = [ { path: 'home', component: HomeComponent }, ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] })

Angular 4 router: prevent direct browser navigation

梦想的初衷 提交于 2019-12-12 08:44:22
问题 How can I convince the Angular 4 router to disable direct browser navigation within my app? I have looked into the router hooks CanActivate and CanDeactivate and implemented them but CanDeactivate does not fire at all when using direct browser navigation. I can use CanActivate to prevent the url but only after the app reboots, which takes time and undesired changes in the browser window. I want to be able to catch the direct browser navigation BEFORE the app reboots. In case this helps: I

Guard always return true

空扰寡人 提交于 2019-12-12 07:03:53
问题 I have two pretty similar guards in angular app. First of them checking is User logged in: // isUser guard export class isUser implements CanActivate { constructor( private fireAuth: AngularFireAuth, private router: Router ) {} canActivate( next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { return this.fireAuth.authState.pipe( take(1), map(authState => !!authState), tap(auth => !auth ? this.router

Error when refreshing child routes, Angular 4

隐身守侯 提交于 2019-12-12 05:47:07
问题 I'm using PathLocationStrategy and the <base href="/"> in index.html. when I go into a child routes like product-detail if I try to refresh the page I get Error: Cannot match any routes, also if I go back and forward with browser. Do I need to switch to HashLocationStrategy to handle refresh? This is child routes. import { Route } from '@angular/router'; import { CustomerDetailComponent } from './index'; export const CustomerDetailRoutes: Route[] = [ { path: 'customer-detail/:code', component

Setting router queryParams in angular 2 do not work

孤街醉人 提交于 2019-12-12 04:57:52
问题 I try to pass an Arry to router queryParams,but it doesn't work every time. this is my code : clickOrg(event) { if (this.idLists[this.idLists.length - 1] != event.id) { this.idLists.push(event.id); this.type = event.type; console.log (this.idLists) this.router.navigate(['userManage'], { queryParams: {idLists:this.idLists,type:this.type} }); } } the result of the log (this.idLists) is right but the router's queryParams didn't update Any help would be appreciated. 回答1: I'm also have a problem

Unable to bind $scope value to view on Url change

痴心易碎 提交于 2019-12-12 04:33:48
问题 I trying to create a search application using angularJS.I am facing the issue in binding $scope values to view when router Url changes. I have a search field in /main.When I write the query and click on search button, the function does the data fetch and assign to a scope variable.The router URL will change to '/Result' and the respective view is displayed.But the view doesn't have the scope values bound. /main and /Result uses the same controller. router code in main module : $routeProvider.

MVC5 and Angular.js routing - URLs not matching

狂风中的少年 提交于 2019-12-12 03:27:11
问题 I'm having some trouble with routing in Angular.js and MVC5. I've simplified it down to the example below. My angular routing code is: app.config(["$routeProvider", "$locationProvider", function ($routeProvider, $locationProvider) { $routeProvider.when("/", { template: "<h1>index</h1>", }) .when("/Home/About", { template: "<h1>about</h1>", }) .when("/Home/Contact", { template: "<h1>contact</h1>", }) .otherwise({ template: "<h1>Error</h1>", }); }]); The MVC Home controller has a method for

When should href be used instead of routerLink in Angular?

时光毁灭记忆、已成空白 提交于 2019-12-12 03:24:27
问题 When I develop in Angular and create views, I always use the routerLink to navigate from one view to another. Recently I have seen important pages made in Angular that use href instead of routerLink to route views on the website. My question is, when is it convenient to use href instead of routerLink in Angular and why? Is it to give the feeling that it is not a SPA? If so, I do not understand it because it loses the full potential of Angular routing. Some examples are https://brandstory.in/

Angular UI-Router testing scope inheritance

早过忘川 提交于 2019-12-12 01:07:26
问题 I am trying to write units tests for a nested state. The state inherits some scope elements from the parent state. In my tests I am creating the controller, which obviously has no visibility of the parent state, and therefore no visibility of the inherited scope items. it('should show the account page', inject(['$controller', 'security', function ($controller, security){ // set up controller with a scope var $scope = $rootScope.$new(); // the parent controller calls this var user = { first: