angular2-directives

What is multi provider in angular2

被刻印的时光 ゝ 提交于 2019-11-30 11:10:43
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 }) 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 registered directives. If multi: true (on the first registered and the new provider) is set, the new directives

How to implement a draggable div in Angular 2 using Rx

Deadly 提交于 2019-11-30 11:05:18
问题 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

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

為{幸葍}努か 提交于 2019-11-30 10:56:39
问题 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

Building a wrapper directive (wrap some content / component) in angular2

徘徊边缘 提交于 2019-11-30 08:56:10
I'm pretty new building directives with Angular2. What I want is to create a popup directive that will wrap the content with some css classes. Content Content can be pure text and headers like: <div class="data"> <h2>Header</h2> Content to be placed here. </div> Then I want to give this a directive attribute like: popup <div class="data" popup> <h2>Header</h2> Content to be placed here. </div> What the directive should do, is to wrap the div inside, lets say: <div class="some class"> <div class="some other class"> <div class="data"> <h2>Header</h2> Content to be placed here. </div> </div> <

Angular2 Dynamic HTML with functional RouterLink

扶醉桌前 提交于 2019-11-30 08:36:02
问题 Long time user, first time question asker! I've been trying to figure this out for the better part of two days to no avail, so here we go. Dynamic compiled templates from external sources in Angular2? I am using http to get page content in the form of HTML from the WordPress API. So I have a template like this: <div [innerHTML]="contentHTML"> </div> and "contentHTML" is a string variable in the component and assigned a value asynchronously via the API call to something like this: <a

Angular2 How to get reference of HTML elements generated dynamically

雨燕双飞 提交于 2019-11-30 08:01:43
I have this inputs generated dynamically: <div *ngFor="let cell of column; let i = index;"> <!-- Material design input--> <md-input id="my-input-{{i}}"> </md-input> </div> Please notice id=my-input-{{i}} I would like to get a reference to the DOM element based on this dynamic id. This input can be 3, 6 or more inputs so I need to access the id dynamically and get a hold to it. The only response is let elem:Element = document.getElementById("myProgrammaticallyChosenIndex") No other angular weird ceremony needed Tested on angular 4+ Syed Ali Taqi Use ElementRef class from @angular/core to get

How to extract ViewContainerRef and ComponentRef in most efficient way?

眉间皱痕 提交于 2019-11-30 07:48:08
问题 I work with angular-material mdSidenav and want to programmatically open it and insert custom component. I use @ViewChild('varName') to extract componentInstance and @ViewChild('varName', {read: ViewContainerRef}) to extract container where I would place my content. So, my question is - is it possible just 1 @ViewChild and get other info from extracted reference. Second question - which values allowed for read property ? ElementRef/ViewContainerRef/... ? Update: I found, that ViewContainerRef

Angular2: Cloning component / HTML element and it's functionality

谁都会走 提交于 2019-11-30 06:09:50
So, the question is fairly simple... I have a table and some angular logic on it (calculating styles, etc)... specifically I have this on THs [class.hidden] = "column.group !== 'key-data' && currentTableView !== column.group" For my table sticky headers functionality I need to clone the table and position it fixed.. using a directive, that does something like this (simplified) let newTable = element.cloneNode(true); body.appendChild(newTable); obviously the angular logic is not applied to the newTable, but I want it to be... How do I do it? Filip Lauc So I did some research and this is what I

How to Unit Test a Directive In Angular 2?

青春壹個敷衍的年華 提交于 2019-11-30 04:45:22
Problem: I would like to be able to unit test a directive in Angular 2 to make sure that it properly compiles. In Angular 1, it was possible to use $compile(angular.element(myElement) service and call $scope.$digest() after that. I specifically want to be able to do this in unit tests so I could test that when Angular ends up running across <div my-attr-directive/> in the code that my-attr-directive compiles. Constraints: Angular 2 using JAVASCRIPT . All sources somewhat related seem to require TS. Perhaps this resource truly does solve the problem and my understanding of TS is just that weak

Angular 2 multiple custom value accessor

时间秒杀一切 提交于 2019-11-30 04:43:49
问题 I am creating an application using angular2. I need to get a Date from user input using a calendar popover, but I need to put a mask on user input to stay in this format dd-mm-YYYY when he is typing. I am using two different modules that I got from web ng-bootstrap and angular2-text-mark <input [textMask]="{mask: mask}" type="text" class="form-control" placeholder="yyyy-mm-dd" name="dp" [(ngModel)]="date" ngbDatepicker #d="ngbDatepicker"> When I use textMask and ngbDatepicker on same tag I