angular2-routing

How to read and write local file using angular 2

假装没事ソ 提交于 2019-12-11 06:45:19
问题 In angular 2, is there any way to read/write files from absolute path? I have used ' filesaver ' library to save the file, where I save the file locally in txt/json format. Example : let blob = new Blob([document.getElementById('exportFile').innerHTML],{ type: "text/plain;charset=utf-8" }); saveAs(blob, "export.json"); Now I want to read and write/edit export.json file. How can I refer it for the next time? Is there any other way or is there any good library available for these operations?

Import modules in the AppModule for separation of concerns in Angular2

十年热恋 提交于 2019-12-11 06:39:08
问题 Templates like from the ASP.NET Core JavaScript services came with a single module called AppModule . Since my application is divided into two logical areas, It seems a good idea to use two modules (AreaA, AreaB) for them. My idea was to import both in AppModule , including shared ressources like Pipes (which can cause trouble here). So for testing purpose, I created a Module called ModuleA import { HomeComponent } from './home/home.component'; import { NgModule } from '@angular/core'; import

Why is an expression in my app.component.html called multiple times?

我的未来我决定 提交于 2019-12-11 06:34:01
问题 I traced the evaluation of an expression in the app.component.html main template and i realized that the trace appeared exactly 5 times each time i refresh or click any page. I then placed a trace in the ngOnInit of app.component.ts and it executes only once as expected... Only the expression in the html file gets called multiple times ! Main routes definitions: const routes: Routes = [ { path: '', redirectTo: '/dashboard', pathMatch: 'full' }, //{ path: '', component: DashboardComponent }, {

Angular2 routing with Asp.net 4.5

瘦欲@ 提交于 2019-12-11 06:09:18
问题 I need a help. I start to develop angular2 with Asp.net core and everything was perfect. For redirecting all 404 request to index.html I use this code in Startup class. app.Use(async (context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value)) { context.Request.Path = "/index.html"; await next(); } }); But, I need to return to asp.net 4.5 and I have now a big problem with routing. I try to use similar code in Owin Startup class

angular2 in-memory-web-api only for a part of an application

自闭症网瘾萝莉.ら 提交于 2019-12-11 06:04:37
问题 I was wondering if is possible to configure angular2 in-memory-web-api only for a part of an application. I want to reach external endpoints for finished components and use in-memory-web-api for components in development stage. I've tried to do this in the folowing two ways: 1 - Loading the data in the main and changing the XHRBackend in the components that I want to reach in-memory endpoints; main.ts bootstrap(AppComponent, [ ... { provide: SEED_DATA, useClass: InMemoryDataService } ]);

Angular2 not loading when directly browsed to route address or on refresh

折月煮酒 提交于 2019-12-11 05:58:14
问题 In the application there is a route defined: const routes: Routes = [ { path: '', component: MainComponent }, { path: 'users', component: UsersComponent } ] In index.html the base href is also correctly defined. <base href="/"> When navigating through application the routes are loaded correctly. But when users enters .../users directly through the browser the application is not loaded and returns 404. Also when the users refresh the webpage (F5), the application is also not loaded. Is there

cannot access to this of component in subscribe function

丶灬走出姿态 提交于 2019-12-11 05:57:20
问题 I'm trying navigate to new page when get answer from server: import {Component} from '../../node_modules/angular2/core'; import {Router} from "../../node_modules/angular2/router"; import {Http, Headers, HTTP_PROVIDERS} from '../../node_modules/angular2/http' @Component({ selector: 'test-page', templateUrl:'src/login/test.html', providers: [HTTP_PROVIDERS] }) export class TestPage { constructor(private _router:Router, private _http:Http) { } Test(username, password) { let body = 'test'; let

Show Load Spinner on Angular2 Route Navigate

社会主义新天地 提交于 2019-12-11 05:48:58
问题 I have seen (this question) and its Answer from @borislemke. Actaully, tried on Angular2 Demo Application but its not changing Loader Div Background color while Navigating to another route. My AppComponent is as follows, import { Component, OnInit } from '@angular/core'; import { Router, ROUTER_DIRECTIVES, NavigationStart, NavigationEnd, NavigationError, NavigationCancel } from '@angular/router'; import {NgClass} from '@angular/common'; import { DialogService } from './dialog.service'; import

angular4 route issue by adding '%2f' character before path

萝らか妹 提交于 2019-12-11 05:47:55
问题 reason of using nested route for me is handling dynamically icon and back button for every page.i have abstract route because when i click to back button route params disappear and i put an abstract path to keep id and questionnaire type parameter in url.my abstract path is Questionaire { path: 'Home', component: HomeComponent,data:{icon:'fa-home'} }, { path: 'QuestionaireList', component: QuestionaireListComponent,data:{icon:'fa-list-ul',previousState:'/Home'} }, { path: 'Questionaire/

Angular 2 canActivate async

回眸只為那壹抹淺笑 提交于 2019-12-11 05:47:14
问题 I have a service which checks does user has permissions to open route. @Injectable() export class GuardService implements CanActivate{ user: User; constructor(private _userService: UserService) { } canActivate(): any{ return this._userService.getUser().subscribe(user => { if(user.user_type == 'admin'){ return true; } return false; }); } But the problem is that it never passes. The problem is in this observable but I don't know how to handle it. How can I achieve this? Thanks in advance 回答1: