angular2-directives

How to use multiple ng-content in the same component in Angular 2?

邮差的信 提交于 2019-11-30 01:22:29
I would like to display different template in my component. Only one will show. If hasURL is true , I want to show the <a></a> . If hasURL is false , I want to show the <button></button> . The problem if hasURL is false, the component show button, but the ng-content is empty. Because it's already read in the first " a></a> Is there a way to solve that please? <a class="bouton" href="{{ href }}" *ngIf="hasURL"> <ng-content> </ng-content> </a> <button class="bouton" *ngIf="!hasURL"> <ng-content> </ng-content> </button> Thanks! You can wrap ng-content in ng-template and use ngTemplateOutlet <a

Uncaught exception in promise when when trying to use nested components

血红的双手。 提交于 2019-11-30 00:27:38
问题 I am getting this exception when trying to use nested components: EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot set property 'endSourceSpan' of null XCEPTION: Error: Uncaught (in promise): TypeError: Cannot set property 'endSourceSpan' of nullBrowserDomAdapter.logError @ angular2.dev.js:23877BrowserDomAdapter.logGroup @ angular2.dev.js:23888ExceptionHandler.call @ angular2.dev.js:1317(anonymous function) @ angular2.dev.js:12763schedulerFn @ angular2.dev.js:13167SafeSubscriber._

Multiple child component inside form - Angular 2

我只是一个虾纸丫 提交于 2019-11-29 23:30:45
问题 I am working on big form, so i plan to truncate the form into multiple child components which helps for easy integration and maitainbility. Using form builder i am trying to implement this. mainform.html <form novalidate (ngSubmit)="onSubmit(formDetail);" [formGroup]="formDetail"> <label> <span>Name</span> <input type="text" placeholder="Enter emp name" formControlName="name"> </label> <app-userinfo></app-userinfo> <!-- Child component 1 --> <app-useracc></app-useracc> <!-- Child component 2

How to implement a draggable div in Angular 2 using Rx

最后都变了- 提交于 2019-11-29 23:09:15
I've been trying to get a draggable div working using Angular 2. I'm using this example from the angular2-examples repo as a starting point, only really adjusting the code to account for the removal of the toRx() method. The code works, but it does not account for mouseout events. This means that if I click on a Draggable div, and move the mouse slowly , the div will move with the mouse. But if I move the mouse too fast, a mouseout event is sent instead of a mousemove event, and the dragging stops. How can I keep the drag going after the mouse is moved so far that a mouseout event is fired? I

How to migrate Angular 2 RC 1 (or earlier) Forms to Angular 2 RC 2 / RC 4 New Forms

你离开我真会死。 提交于 2019-11-29 19:19:03
问题 I need to migrate my existing Angular 2 RC 1 app to Angular 2 RC 4. As a part of which I also need to move my existing forms to Angular 2 RC 4 New Forms. Can anyone please guide, how to update existing forms to new form. 回答1: For those who are having trouble in migrating forms from Angular 2 RC 1 (or earlier) to Angular 2 RC 2 / RC 4 New Forms. Here are the steps they need to follow: Include new forms in your project by adding below package to their packages.json: "@angular/forms": "0.2.0",

What is multi provider in angular2

余生颓废 提交于 2019-11-29 16:09:21
问题 I understand that provider is for getting service from another class but what is multi-provider and token thing? And also when we do multi=true ? provide(NG_VALIDATORS, { useExisting: class), multi: true }) 回答1: multi: true means that one provider token provides an array of elements. For example all directives for router support routerLink , router-outlet are provided by ROUTER_DIRECTIVES . If a new provider is registered with the token ROUTER_DIRECTIVES , then it overrides the previously

Angular 2 async pipe not rendering/updating Observable data automatically

喜欢而已 提交于 2019-11-29 15:54:31
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]); Here is the root component: import {Component} from 'angular2/core'; import {RouteConfig, ROUTER

Get the width, height and offset of clicked div - Angular 2

梦想与她 提交于 2019-11-29 15:00:24
I have a template that creates a list of links using *ngFor and a separate div element that I want to change its location based on the currently active link. Template: <div #divHandle *ngFor="let link of links; let i = index" class="div-link" (click)="changeActiveLink(i)"> <h2>{{link}}</h2> </div> <div [@indexState]="activeLink" id="highlighter"></div> This results in a structure like so: <div class="div-link"> <div (click)="changeActiveLink(0)"><h2>Link 1</h2></div> <div (click)="changeActiveLink(1)"><h2>Link 2</h2></div> <div (click)="changeActiveLink(2)"><h2>Longer link 1</h2></div> <div

Add a component dynamically to a child element using a directive

橙三吉。 提交于 2019-11-29 14:46:41
Trying to place a component dynamically to a child element, using a directive. The component (as template): @Component({ selector: 'ps-tooltip', template: ` <div class="ps-tooltip"> <div class="ps-tooltip-content"> <span>{{content}}</span> </div> </div> ` }) export class TooltipComponent { @Input() content: string; } the directive: import { TooltipComponent } from './tooltip.component'; @Directive({ selector: '[ps-tooltip]', }) export class TooltipDirective implements AfterViewInit { @Input('ps-tooltip') content: string; private tooltip: ComponentRef<TooltipComponent>; constructor( private

Angular2: Parent and Child Components Communication

心不动则不痛 提交于 2019-11-29 14:38:05
I'm trying to create a parent and child component where the child component is going to have a states drop down. Can someone help me understand how I can access the states drop down value in Parent Component? Here is my sample code. /app/app.ts import {Component} from 'angular2/core' import {FORM_DIRECTIVES, FormBuilder, ControlGroup, Validators} from 'angular2/common' import {State} from './state' @Component({ selector: 'my-app', providers: [FormBuilder], templateUrl: 'app/app.html', directives: [State] }) export class App { registrationForm: ControlGroup; state: State; constructor(fb: