angular2-directives

Use content of component template in angular 2 [duplicate]

梦想与她 提交于 2019-12-11 11:49:59
问题 This question already has answers here : Custom template(transclusion without ng-content) for list component in Angular2 (3 answers) Closed 3 years ago . RE DUPLICATE: "This question has been asked before and already has an answer. " So this question was asked 10 days after I asked it? Somebody doesn't know how to read time stamps. I'm struggling with Angular 2 making it hard or perhaps impossible to do things that were trivial in Angular 1, especially without tons of superfluous code and/or

Can't resolve all parameters for custom directive

回眸只為那壹抹淺笑 提交于 2019-12-11 07:01:22
问题 I created a custom directive to open a link in a new tab, when running in ng serve, it works. However, when I tried in ng build --prod, it showed this error: ERROR in Can't resolve all parameters for OpenLinkInNewTabDirective in C:/Users/myApp/src/app/directives/open-link-in-new-tab.directive.ts: ([object Object], ?). Here is the directive: import { Directive, ElementRef, HostListener, Input, Inject } from '@angular/core'; @Directive({ selector: '[newTab]' }) export class

Using vanilla js code in Angular 2 (angular-cli)

∥☆過路亽.° 提交于 2019-12-11 06:53:54
问题 I am trying to implement the Vanilla Tilt JS plugin in my project, but I can't even seem to find a way of using vanilla js imports in my project. So far, I have tried using it as a directive, just like you would use a jQuery plugin by using ElementRef , Input etc. from @angular/core . I have included the script in my .angular-cli.json file under scripts: directly from the npm package that I have installed for Vanilla Tilt JS. And I was thinking about using it as a directive, since it has its

Angular2+ render a component without any wrapping tag at all

半腔热情 提交于 2019-12-11 05:42:08
问题 My child-component looks like: ... @Component({ selector: '[child-component]' templateUrl: './child.template.html' }) ... and my parent template like: <span child-component [someInput]="123"></span> now I want to render the content of my child component without the <span> container around it. I want no container at all in my parent component's template, just the content of our child-component's template. I tried some other tags already. <ng-content> (nothing rendered at all) <ng-template>

Why the ngStyle directive is declared into the []?

时间秒杀一切 提交于 2019-12-11 04:19:48
问题 I am an absolute beginner with Angular 2 and I have the following dount related the correct syntax of the ngStyle directive. I have this example (that works fine): <p [ngStyle]="{backgroundColor: getColor()}">Server with ID {{ serverID }} is {{ getServerStatus() }}</p> I know that, in this case, the ngStyle directive is adding something like to: style="background-color: green;" at my HTML paragraph. My doubt is related the correct meaning of this syntax. Why is it: [ngStyle]="{backgroundColor

Angular listen for enable/disable elements

和自甴很熟 提交于 2019-12-11 04:03:41
问题 I am trying to find out if an element is disabled in an Angular directive. I am trying with host listeners so far no luck Directive: @HostBinding('attr.disabled') isDisabled : boolean; @HostListener("disabled") disabled() { if(this.isDisabled) { // do some action } } It's working for me with the setter @Input('disabled') set disabled(val: string) { if(val) { this.elementRef.nativeElement.setAttribute('disabled', val); } else { this.elementRef.nativeElement.removeAttribute('disabled'); } } but

Observable of Component Attribute Changes in Angular2

陌路散爱 提交于 2019-12-11 03:02:35
问题 When creating a component in angular 2 that has inputs attributes via @Input, how can I get an observable from the changes made to that attribute @Input (not to be confused with user form input). export class ExampleComponent implement OnChanges{ @Input() userObject: User; ngOnChanges(changes: any): void{ // Validate that its the 'userObject' property first this.doStuff() } } In practice, I would like to merge the Observable changes of the userObject with the Observable changes of other

How to watch from directive on a simple variable changes inside a service?

∥☆過路亽.° 提交于 2019-12-11 01:49:45
问题 I have a simple service with data variable: import { Injectable } from '@angular/core'; @Injectable() export class MyService { private _data:number; get data(): number { return this._data; } set data(value: number) { this._data = value; } } Now from a directive I would like to catch whenever someone is doing set to my variable: this.myService.data = 12345; I was trying to do that with subscribe but missing something on syntax: this.myService.data.subscribe(res => console.log(res)); What am I

Angular 2 - Two way communication between components

一世执手 提交于 2019-12-11 01:49:44
问题 I've this code...It's a sample tutorial application I'm trying to build that's reflect the daily basis needs of a developer. Actually, when the user types "fire" on the parent component, the child execute an event that's sends to the parent the word "booom" - It's a sample to demonstrate communication between a child component sending messages to a parent component using @Input and OnChanges. Now, I'm trying to do different: The parent should with some how tell to the child a message like

Angular2 No provider for Renderer! (NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)

£可爱£侵袭症+ 提交于 2019-12-10 20:49:13
问题 I custom modal of customModal.ts in shlomiassaf/angular2-modal. Specific, i add a input contain ngModel, it imported FORM_DIRECTIVES and directives. The issue when run 'No provider for Renderer! (NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)' Please help me resovle this issue. Thanks. 回答1: I see two possibilities: The corresponding provider isn't specified at the component or application level. I don't think that the problem because I already inject a Renderer without