angular2-routing

Get a reference to a component of current route in Angular 2's router?

一曲冷凌霜 提交于 2019-12-30 18:38:11
问题 Is there a clean way to get a reference to the component of current route? This seems to work, but seems very hacky: this.router.currentInstruction. component.componentType.prototype.somePropertyOrFunction(); 回答1: In fact, you don't have access to the component instance associated to the current route with your expression. You only get the component type. That's why you need to use the prototype but you get a reference to function and don't reference to methods of the component instance. The

Angular 2: Testing components with router

▼魔方 西西 提交于 2019-12-30 18:21:08
问题 I am writing the simplest component that is using a routeLink: @Component({ selector: 'memorySnippet', templateUrl: '<div class="memory-snippet-wrapper" *ngIf="memory" [routerLink]="['MainPanel', 'MemoryPanel', {'id' : this.memory.id}]">', directives: [CORE_DIRECTIVES, ROUTER_DIRECTIVES] }) export class MemorySnippetComponent { @Input() memory: Memory; } The problem occurs when I try testing this component. The moment I add the router link Karma is complaining about missing providers: After

Angular 2: Testing components with router

夙愿已清 提交于 2019-12-30 18:21:01
问题 I am writing the simplest component that is using a routeLink: @Component({ selector: 'memorySnippet', templateUrl: '<div class="memory-snippet-wrapper" *ngIf="memory" [routerLink]="['MainPanel', 'MemoryPanel', {'id' : this.memory.id}]">', directives: [CORE_DIRECTIVES, ROUTER_DIRECTIVES] }) export class MemorySnippetComponent { @Input() memory: Memory; } The problem occurs when I try testing this component. The moment I add the router link Karma is complaining about missing providers: After

Angular 2 Router - named router-outlet navigation from code

大城市里の小女人 提交于 2019-12-30 17:37:10
问题 Using @angular/router": "3.4.7". Proposed solution here doesn't work anymore. /** The ProductComponent depending on the url displays one of two info components rendered in a named outlet called 'productOutlet'. */ @Component({ selector: 'product', template: ` <router-outlet></router-outlet> <router-outlet name="productOutlet"></router-outlet> ` }) export class ProductComponent{ } @NgModule({ imports: [ CommonModule, RouterModule.forChild([ { path: 'product', component: ProductComponent,

Forward Slash in Angular Route Parameters

最后都变了- 提交于 2019-12-30 09:56:06
问题 How do I set up my routes so that my parameter can take forward slashes? For example: myapp.com/file/rootfolder/subfolder/myfile This doesn't work: const SECTION_ROUTES: Routes = [ { path: 'file/:path', component: FileStoreComponent } ]; Is having / in routing parameter values possible? I've read about URL approaches that use URL encoding. However, I'd like my user to be able to type the URL. 回答1: It looks like you have to escape each forward slash with a wildcard like so: /*page This

Load scripts through all components in Angular 2

北城余情 提交于 2019-12-30 07:25:11
问题 I have been using Angular 2 with AdminLTE which needs to run some scripts to load properly. So I have added them in in my .anglular-cli.json : "scripts": [ "../node_modules/jquery/dist/jquery.min.js", "../node_modules/bootstrap/dist/js/bootstrap.min.js", "../node_modules/admin-lte/dist/js/adminlte.min.js", "../node_modules/moment/min/moment.min.js" ], Unfortunately, this does not work all time. The page loads fine the first time but when I route to another page, scripts are not reloaded for

Twitter widget on Angular 2

杀马特。学长 韩版系。学妹 提交于 2019-12-30 07:23:31
问题 I created a Twitter widget and I'm trying to put it in my Angular 2 project, but the JS file does not work. If I insert it with JS (Here) it works, but when I switch to another tab and back (I have Angular Routing installed) it disappears and shows whatever is in A tag (so, "Tweets by ..."). HTML code (it's in home component): <md-card-content> <a class="twitter-timeline" data-lang="en" data-height="350" data-theme="light" data-chrome="noborders nofooter noheader noscrollbar transparent" href

How do I extend RouterOutlet when using the new router in RC.1

折月煮酒 提交于 2019-12-30 06:33:31
问题 I can't seem to extend RouterOutlet when using the new router in RC.1 Example: import { Directive } from '@angular/core'; import { Router, ROUTER_DIRECTIVES, RouterOutlet } from '@angular/router'; @Directive({ selector: 'router-outlet' }) export class RouterOutletDirective extends RouterOutlet { } The error: @angular/router/index"' has no exported member 'RouterOutlet'. Am i doing something wrong or is this broke with the new router in RC.1? Updated: import { Directive, Attribute,

Template parse error: Unexpected closing tag

坚强是说给别人听的谎言 提交于 2019-12-30 06:23:07
问题 I'm getting an error when reloading some of the routes in my app. First load works fine http://localhost:8001 , and all other routes work from there. But if I reload page on some other route I get an exception below... For example: http://localhost:8001 works http://localhost:8001/application works http://localhost:8001/application/ doesn't work http://localhost:8001/application/add doesn't work Anyone knows why is this happening? EXCEPTION: EXCEPTION: Template parse errors: Unexpected

MVC 6 Routing, SPA fallback + 404 Error Page

随声附和 提交于 2019-12-30 04:38:04
问题 With RC1 of ASP.NET Core 1.0's MVC 6 you can map routes from within your Startup.Configure function when invoking app.UseMvc . I have mapped a "spa-fallback" route that will ensure that the HomeController and Index view are the defaults like so: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { // ... omitted for brevity app.UseExceptionHandler("/Home/Error"); app.UseStatusCodePagesWithRedirects("/Home/Error/{0}"); app.UseMvc(routes => {