angular2-template

Angular2 - Template reference inside NgSwitch

做~自己de王妃 提交于 2019-12-07 16:06:59
问题 I have a NgSwitch template. In the NgSwitch I want to get a template reference to the initialized template. Something like this: <div class="container" [ngSwitch]="model.type"> <first-component #ref *ngSwitchCase="0"></first-component> <second-component #ref *ngSwitchCase="1"></second-component> <third-component #ref *ngSwitchCase="2"></third-component> </div> When clicking on a button in the component I want to call to the initialized component (first/second/third) to a method (which defined

Using pipe name as a variable in the template in Angular2

心已入冬 提交于 2019-12-07 10:13:30
问题 I am struggling with using a standard angular2 pipe in a non-standard way and I was wondering if there are any ways around it. Assume I have a variable which its value equals the definition of a standard pipe, for example, the common "date:'medium'" pipe. let a = "date:\':medium\'"; Now, somewhere in my html, I would like to be able to use this "a" variable the following way: <p>{{myRecord.date | a}}</p> And I want this "a" to have the same effect of the date pipe it contains. Is there any

How to wrap template using ngForTemplate?

喜夏-厌秋 提交于 2019-12-07 07:41:18
问题 I try to make ListView component using ngForTemplate for custom templates list-view.component.html <div class="list-view"> <template ngFor [ngForOf]="items" [ngForTemplate]="template"> </template> </div> list-view.component.ts @Component({ selector: 'm-list-view', styleUrls: ['./list-view.component.less'], templateUrl: './list-view.component.html' }) export class ListViewComponent { @Input() items: any[] = []; @ContentChild(TemplateRef) template: any; } When I use it like this: <m-list-view

Pre Populate input filed in `FormGroup` - Angular2

佐手、 提交于 2019-12-07 02:49:16
问题 I am using Angular2 - Reactive Forms. Everything works fine until i want to show a pre-populated value in one of fields in Form. Scenario: There are multiple buttons on a page and each button opens up a form with fields as Name Email Message Product Code --> Value for this shall be prepopulated as per item code from service. Failing Scenario: Product Code input value turns to null. TS Code: import { FormGroup, FormBuilder, Validators } from '@angular/forms'; queryForm: FormGroup; constructor

Angular2 local components / template reuse

和自甴很熟 提交于 2019-12-07 00:50:06
问题 I'm writing some Angular2 templates that have repetitive portions with different containers. In this case, the view can change if things are grouped and if multi section mode is enabled. Please excuse the long example, but something like this: <template [ngIf]="isCategoryGrouped"> <div *ngFor="#categories of categories"> <div>{{ categories.category.name }}</div> <div *ngFor="#thing of categories.things"> <label *ngIf="isMultiSelectMode"> <input type="checkbox" (change)="updateThingSelection

Can I add two template for one component in angular2?

这一生的挚爱 提交于 2019-12-06 22:07:19
问题 I have one component with one html and .ts file. For some reasons I have to create multiple pages (HTML) pages. Is it possible to create multiple (html) pages for single class (component)? Or is it possible to provide dynamic TemplateUrl to the component? My main motive is to provide different URL and to use different view (HTML pages) but using single class (.ts class i.e component)? I have seen many questions referred below related to that but unable to found exact solution- Dynamic

Pass NavigationExtras to routerLink in template

青春壹個敷衍的年華 提交于 2019-12-06 21:30:32
问题 I want to disable changing the URL when routing in my Angular 2 app. I know that skipLocationChange: true has to be passed as a NavigationExtras parameter to the router. My question is: Is it possible to pass NavigationExtras to a routerLink from inside the template? What I have tried: <h1> {{title}} </h1> <ul> <li><a [routerLink]="['route1', { skipLocationChange: true }]">Route1</a></li> <li><a [routerLink]="['route2', { skipLocationChange: true }]">Route2</a></li> </ul> <router-outlet><

Angular 2: Module not found: Error: Can't resolve

拥有回忆 提交于 2019-12-06 18:55:49
问题 I have a simple app created with Angular-CLI, I wanted to refactor and move the app.component.ts code in separate component file and started to get a nasty error: Module not found: Error: Can't resolve on './sb/sb.component.html' ( my SBComponent). Under the This what i have: app.module: import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import {

Angular 2 Change Class On Condition

荒凉一梦 提交于 2019-12-06 17:45:42
问题 I have three buttons in a view and on page load I am displaying the first buttons content. Once a button is clicked the button becomes active but on page load the initial button is not set to active. In order to show the first button active I added this to the div: [ngClass]="'active'" The problem with this is now when another button is clicked the first button keeps the active class. I am evaluating the data being show based on a string. On click of each button the string changes. How can I

TypeError: Cannot create property 'validator' on string 'abc@gmail.com' at setUpControl

寵の児 提交于 2019-12-06 17:06:12
问题 I face issue in formGroup . First Based on URL I take some value and call to API for retrieve particular user-data for pre-field text. register.html <form [formGroup]="form" (ngSubmit)="onSubmit(form.value)" class="form-horizontal"> <div class="form-group row"> <label for="inputEmail3" class="col-sm-4 ">Username</label> <div class="col-sm-8"> <input [formControl]="email" type="text" class="form-control" id="inputEmail3" placeholder="Email Address" [readonly]="isReadOnly"> </div> </div> </form