angular2-template

Angular2 issue: There is no directive with “exportAs” set to “ngForm”

為{幸葍}努か 提交于 2019-12-05 16:40:31
I 'am facing this frustrating issue There is no directive with "exportAs" set to "ngForm" (" ]#f="ngForm" (ngSubmit)="onSubmit(f)" class="form-horizontal"> "): ng:///ComponentsModule/EquipeComponent.html@8:12 Error: Template parse errors: There is no directive with "exportAs" set to "ngForm" (" ]#f="ngForm" (ngSubmit)="onSubmit(f)" class="form-horizontal"> "): ng:///ComponentsModule/EquipeComponent.html@8:12 This is what my app.module.ts contains import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { LocationStrategy, HashLocationStrategy

Angular2 : No provider for String! (child -> String) in [Array in parent

一个人想着一个人 提交于 2019-12-05 16:13:05
Im building basic Todo App in angular2 when I click add button to send data from parent to child using input I get No provider for string! (child->string), and no data displayed only button at the child class is shown, what does it mean here is parent component: @Component({ selector : 'parent-component', directives : [child], template : ` <h1 class= "text-center">ToDo App</h1> <div class = "form-group"> <lable>Task</lable> <input type = "text" class = "form-control" #task> <lable>Detail</lable> <input type = "text" class = "form-control" #detail > <button type = "submit" class = "btn btn

ViewChild and focus()

ぃ、小莉子 提交于 2019-12-05 15:55:43
I have a component which contains a textarea which is hidden by default : <div class="action ui-g-2" (click)="toggleEditable()">edit</div> <textarea [hidden]="!whyModel.inEdition" #myname id="textBox_{{whyModel.id}}" pInputTextarea focus="true" [(ngModel)]="whyModel.description"></textarea> When I click on the "edit" div I want to show the textarea and put focus on it : @ViewChild('myname') input: ElementRef; ... private toggleEditable(): void { this.whyModel.toggleEditable(); this.input.nativeElement.focus(); } The "show" part is working but not the focus part. What do I miss? Bindings are

Using pipe name as a variable in the template in Angular2

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 15:49:55
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 way to achieve this? 来源: https://stackoverflow.com/questions/43788650/using-pipe-name-as-a-variable-in

Bind Select List with FormBuilder Angular 2

為{幸葍}努か 提交于 2019-12-05 13:52:40
In Angular 2, creating a simple app but when formBuilder is attached with DOM control in case of select list , First option is coming blank - even if I provided some initial value in formBuilder that value is not coming to DOM element Before FomBuilder Select List Genral LDAP After FomBuilder Select List No option appearing initially Genral LDAP File 1 - form.component.ts import { Component } from '@angular/core'; import { FormBuilder, Validators, REACTIVE_FORM_DIRECTIVES, FormGroup, FormControl } from '@angular/forms'; @Component({ moduleId : module.id, selector : 'login', templateUrl :

What's the difference between ref- prefix and # in Template reference variable (Angular 2)

ぐ巨炮叔叔 提交于 2019-12-05 12:20:39
I want to understand the difference between template reference variable notations as mentioned below in the input text boxes. <input type="text" name='name' #name [(ngModel)]='model'> <input type="text" name='name' ref-name [(ngModel)]='model'> What's the difference between using #name and ref-name . Does the scope of the variable changes on using ref-name ? Can anybody please suggest the best practice and reason ? They are two different syntaxes for literally exactly the same thing. You can think of it this way: some people (and editors) don't like the new '#variable' syntax, so Angular

How to trigger Angular 2 form submit from component?

十年热恋 提交于 2019-12-05 12:13:21
问题 Basically, I have <form #f="ngForm" (ngSubmit)="save(f.form)" #formElement> ... <button class="btn btn-primary" #saveButton>Save</button> </form> I want to be able to trigger submit() from the component. I've tried @viewChild('formElement') and renderer.invokeElementMethod to trigger click() . 回答1: NgForm has property ngSubmit which is EventEmitter. So doing emit() on this property from the component will trigger a submit. Also you need to use your f variable instead of formElement because f

Event delegation in Angular2

Deadly 提交于 2019-12-05 11:58:03
问题 I'm developing an app in ng2 and I'm struggling with something. I'm building a calendar where you can pick a date-range and I need to react on click & mouseenter/mouseleave events on day cells. So I have a code (simplified) like this: calendar.component.html <month> <day *ngFor="let day of days" (click)="handleClick()" (mouseenter)="handleMouseEnter()" (mouseleave)="handleMouseLeave()" [innerHTML]="day"></day> </month> But this gives me hundreds of separate event listeners in the browser's

How to wrap template using ngForTemplate?

本小妞迷上赌 提交于 2019-12-05 11:52:07
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 [items]="categories"> <template let-item="$implicit"> **some HTML markup** </template> </m-list-view>

How can I use NgFor without creating arrays to generate matrix UI pattern

此生再无相见时 提交于 2019-12-05 11:22:23
I would like to implement UI matrix pattern, which should generate dynamically. By receiving input parameter it should decide what would be UI matrix pattern dimensions: For example 9X3 elements: pattern 9x3 elements I use Angular2.js, typescript, SCSS. html tamplate and .ts looks: import {Component, Input, OnInit} from 'angular2/core'; import {NgFor} from 'angular2/common'; @Component({ selector : 'game-pattern', moduleId : module.id, templateUrl: 'game-pattern.component.html', styleUrls : ['game-pattern.component.css'], directives : [NgFor], }) export class GamePatternComponent implements