angular2-routing

Passing Multiple route params in Angular2

守給你的承諾、 提交于 2020-03-17 04:17:46
问题 Is it possible to pass multiple route params e.g. like below need to pass id1 and id2 to the component B @RouteConfig([ {path: '/component/:id :id2',name: 'MyCompB', component:MyCompB } ]) export class MyCompA { onClick(){ this._router.navigate( ['MyCompB', {id: "someId", id2: "another ID"}]); } } 回答1: OK realized a mistake .. it has to be /:id/:id2 Anyway didn't find this in any tutorial or other StackOverflow question. @RouteConfig([{path: '/component/:id/:id2',name: 'MyCompB', component

Angular 7 Hide bootstrap modal in typscript

怎甘沉沦 提交于 2020-03-05 09:34:21
问题 I want to call (click)="basicModal.hide()" methode of MDBootstrap Modal inside one of my fuctions in my typescript component. I don't know how to access this method from component. <button type="button" mdbBtn color="primary" class="relative waves-light" (click)="basicModal.show()" mdbWavesEffect>Launch demo modal</button> <div mdbModal #basicModal="mdbModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myBasicModalLabel" aria-hidden="true"> <div class="modal-dialog" role=

Can't access to my method delete of my api rest

风流意气都作罢 提交于 2020-02-25 05:55:25
问题 I'm not able to access to my delete method of my api rest. If i write the method like this it work: [Route("api/Document/{documentId:int}")] [HttpDelete] public IHttpActionResult Delete([FromUri]int documentId,[FromBody] int [] documentsId) { try { documentCtrl = documentCtrl ?? new DocumentCtrl(); return Ok(documentCtrl.Delete(documentsId)); } catch (DocumentNotFoundException) { return NotFound(); } catch (Exception) { return InternalServerError(); } } It works, but if i put: [Route("api

Can't access to my method delete of my api rest

a 夏天 提交于 2020-02-25 05:55:09
问题 I'm not able to access to my delete method of my api rest. If i write the method like this it work: [Route("api/Document/{documentId:int}")] [HttpDelete] public IHttpActionResult Delete([FromUri]int documentId,[FromBody] int [] documentsId) { try { documentCtrl = documentCtrl ?? new DocumentCtrl(); return Ok(documentCtrl.Delete(documentsId)); } catch (DocumentNotFoundException) { return NotFound(); } catch (Exception) { return InternalServerError(); } } It works, but if i put: [Route("api

How do I dynamically load and display html which contains routerLink directives in Angular 2?

旧时模样 提交于 2020-02-22 06:21:45
问题 I have an Angular 2 component which, on some user action, loads html from a database. The html contains anchor tags with relative paths. Given that I don't want the whole application to reload when the user clicks the link, I am trying to use the routerLink directive; however, since this html is loaded dynamically, the routerLink is not processed. The html will not contain any other angular directives. What is the simplest way to achieve this? See my example below. import { Component } from '

Get instance of component on active route in Angular2's router?

◇◆丶佛笑我妖孽 提交于 2020-02-20 08:48:29
问题 I know that ActivatedRouteSnapshot.component in Angular2 contains the reference/class to the activated route if I call Router.routerState.snapshot but how to get for the component class the current (or minimal: one created) instance for it? Injector.get(..) does not return instances of components and creating a new instance of a component does also not help (me). 回答1: You can use <router-outlet (activate)='onActivate($event)' (deactivate)='onDeactivate($event)'></router-outlet> where $event

Get instance of component on active route in Angular2's router?

浪尽此生 提交于 2020-02-20 08:48:09
问题 I know that ActivatedRouteSnapshot.component in Angular2 contains the reference/class to the activated route if I call Router.routerState.snapshot but how to get for the component class the current (or minimal: one created) instance for it? Injector.get(..) does not return instances of components and creating a new instance of a component does also not help (me). 回答1: You can use <router-outlet (activate)='onActivate($event)' (deactivate)='onDeactivate($event)'></router-outlet> where $event

Angular testing router params breaks test bed

纵饮孤独 提交于 2020-02-19 07:19:30
问题 When I provide params to my TestComponent the test bed blows up if the html contains a [routerLink] testbed setup TestBed.configureTestingModule({ imports: [SharedModule.forRoot(), ManagementModule, HttpModule, RouterModule.forRoot([{ path: '', component: TestComponent }])], declarations: [TestComponent], providers: [ BaseRequestOptions, MockBackend, { provide: Http, useFactory: function (backend: MockBackend, defaultOptions: BaseRequestOptions) { return new Http(backend, defaultOptions); },

Angular testing router params breaks test bed

末鹿安然 提交于 2020-02-19 07:18:22
问题 When I provide params to my TestComponent the test bed blows up if the html contains a [routerLink] testbed setup TestBed.configureTestingModule({ imports: [SharedModule.forRoot(), ManagementModule, HttpModule, RouterModule.forRoot([{ path: '', component: TestComponent }])], declarations: [TestComponent], providers: [ BaseRequestOptions, MockBackend, { provide: Http, useFactory: function (backend: MockBackend, defaultOptions: BaseRequestOptions) { return new Http(backend, defaultOptions); },

Change a HTML element in app.component dynamically

爷,独闯天下 提交于 2020-02-08 07:08:26
问题 I have implemented angular2 routing and its working perfect. Then i got this crazy thought and couldn't find a solution for that. Question : I have an app.component.html page with a navbar and a jumbotron bootstrap element. The navbar has two links, one for home page , and the other for settings page . I need to change the jumbotron element to display " You are in Home page " from the HomeComponent variable when home link is clicked and display " You are in Settings page " from the