angular2-template

Implementing Dynamic Routing in Angular2 (Typescript) [duplicate]

天大地大妈咪最大 提交于 2019-12-30 01:30:19
问题 This question already has answers here : Async load routes data and build route instruction for Angular 2 (4 answers) Closed 3 years ago . RouteConfig class which can be used to decorate a component (@RouteConfig) with routing capabilities has certain route definitions defined for that component. Now, the catch is to have these route definitions injected at runtime (dynamically). The reason being, let's say I have an application wherein I have to display (UI) and define (decorate) 'n' number

Angular 2 async pipe not rendering/updating Observable data automatically

孤街浪徒 提交于 2019-12-29 09:13:29
问题 I am facing an issue with the Angular2 router and an async pipe. I am trying to render an RxJs Observable and the data does not render automatically. One has to click on the link for the route for the data to render. Here is the root app: import {bootstrap} from 'angular2/platform/browser'; import {HTTP_PROVIDERS} from 'angular2/http'; import {ROUTER_PROVIDERS} from 'angular2/router'; import {AppComponent} from './app.component.ts'; bootstrap(AppComponent, [HTTP_PROVIDERS, ROUTER_PROVIDERS]);

Angular 2 async pipe not rendering/updating Observable data automatically

核能气质少年 提交于 2019-12-29 09:13:12
问题 I am facing an issue with the Angular2 router and an async pipe. I am trying to render an RxJs Observable and the data does not render automatically. One has to click on the link for the route for the data to render. Here is the root app: import {bootstrap} from 'angular2/platform/browser'; import {HTTP_PROVIDERS} from 'angular2/http'; import {ROUTER_PROVIDERS} from 'angular2/router'; import {AppComponent} from './app.component.ts'; bootstrap(AppComponent, [HTTP_PROVIDERS, ROUTER_PROVIDERS]);

Angular 2 Routing Does Not Work When Deployed to Http Server

限于喜欢 提交于 2019-12-29 03:25:08
问题 I am going to develop a simple Angular 2 application. I have created a project with routing, using Angular CLI and added several components to the app using 'ng generate component ' command. Then I specified routing in the app-routing.module.ts as following. import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { HomeComponent } from './home/home.component'; import { AboutComponent } from './about/about.component'; import { UserComponent }

*ngFor Behaviour on primitive data type

a 夏天 提交于 2019-12-29 00:46:06
问题 I have a list of objects which I am displaying using a *ngFor on the HTML page. Now the user interacts with UI and changes one of the primitive values(boolean, from false to true). As per my understanding the *ngFor will only render the changes if the list object is modified completely i.e. removed and added again to the list. If I am right on this concept, then can you please suggest a method to reflect the change in the primitive type without re-initializing the component or modifying the

Angular 2 binding/events not working when adding template as innerHTML

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-28 03:13:19
问题 I am trying to create a reusable table which can be configurable. The cells can be configured to have html template. I am configuring the column " Review " to have html template with anchor tag with click event (review(row)). So far I tried to insert this template as innerHTML, but then none of the angular binding works. Then I tried to create a dynamically invoked component (review.component.ts) but this component invoked only once for first row. Moreover I didn't find any way to pass the

<ng-container> vs <template>

北慕城南 提交于 2019-12-28 01:41:13
问题 ng-container is mentioned in Angular 2 documentation but there is no explanation how it works and what are use cases. It is particularly mentioned in ngPlural and ngSwitch directives. Does <ng-container> do the the same thing as <template> , or it depends whether a directive was written to use one of them? Are <ng-container *ngPluralCase="'=0'">there is nothing</ng-container> and <template [ngPluralCase]="'=0'">there is nothing</template> supposed to be the same? How do we choose one of them?

How to instantiate and apply directives programmatically?

和自甴很熟 提交于 2019-12-28 01:35:14
问题 I know that in ng2 we have ComponentFactoryResolver that can resolve factories that we can apply to a ViewContainerRef . But, is there something similar for directives? a way to instantiate them and apply them to the projected content from a component? 回答1: No, directives can't be added or removed dynamically. They are only applied to HTML statically added to component templates. What you could do is to enable/disable the directive by passing a parameter ( @Input() ) to the directive to

Toggle button based on json response in angular 2

风格不统一 提交于 2019-12-25 18:14:35
问题 I am trying to toggle button based on backend response.If the response is Yes, toggle button should be ON, if the response is No, toggle button should be off. Below is my html code <div class="btn-group btn-toggle"> <button class="btn btn-sm btn-default">ON</button> <button class="btn btn-sm btn-primary ">OFF</button> </div> Below is my component code, where i calling a get service which returns response either Yes or No.I am calling the service in ngOnit() because i want to check whether the

Angular2 refresh router-outlet

自古美人都是妖i 提交于 2019-12-25 09:19:47
问题 I'm working on a CRM and I have a select box in the header which allows the user to change the current user, In addition, the main content is inside the router-outlet. When the user select another user I want to refresh the page but only the router-outlet so the info will be for the new user I saw that other CRMs just redirect the user to the dashboard / index page, but I want to keep the user on the same page. 回答1: You should have a function in a service import {Subject} from 'rxjs/Subject';