angular-directive

Can a directive delete itself from a parent scope

旧巷老猫 提交于 2019-12-04 10:41:02
问题 Let's say I have the following code <div ng-app="app" ng-controller="controller"> <div ng-repeat="instance in instances> <customDirective ng-model="instance"></customDirective> </div> </div> And my custom directive has an isolated scope, defined as: app.directive('customDirective', function($log) { return { restrict: 'E', templateUrl: './template.htm', scope: {_instance:"=ngModel"}, link: function($scope) { .... } }); In this directive, I have to option to delete it. My question is how can I

Angular 4 directive error: Can't resolve all parameters for directive

孤街浪徒 提交于 2019-12-04 09:49:12
I'm totally new to Angular and trying to inject basic structural directive from Angular guide. Here is my directive: import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core'; @Directive({ selector: '[pcDropdown]' }) export class DropdownDirective { private hasView = false; constructor( private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef, private items ) { } @Input() set pcDropdown(condition: boolean) { if (!condition && !this.hasView) { this.viewContainer.createEmbeddedView(this.templateRef); this.hasView = true; } else if (condition && this

How to prevent double click in Angular?

故事扮演 提交于 2019-12-04 03:21:12
I have a component with click . <my-box (click)="openModal()"></my-box> When I click this element, openModal function will run. And I'd like to give 1000ms throttle time in order to prevent opening multiple modals. My first approach was using Subject (from rxJs) //html <my-box (click)="someSubject$.next()"></my-box> //ts public someSubject$:Subject<any> = new Subject(); ...etc subscribe But I feel it's a bit verbose. Next Approach was using a directive . I modified a bit of code that I found by googling. //ts import {Directive, HostListener} from '@angular/core'; @Directive({ selector: '

Angular Animations : How to bind animation trigger name dynamically in the template?

帅比萌擦擦* 提交于 2019-12-04 02:27:54
问题 I would like to know if there is a way to bind the animation trigger name dynamically in the template. Here is the div to animate in the template app.component.html : <div [@animationTriggerName]> ... </div> Here is the app.module.ts : ... @NgModule({ imports: [...], declarations: [ ..., AnimationTriggerNameDirective ], bootstrap: [...] }) And here is the app.component.ts : @Component({ ... }) export class AppComponent { ... animationTriggerName = 'slideInOut'; } @Directive({ selector: '

Difference between ngStorage and $window.localStorage

穿精又带淫゛_ 提交于 2019-12-03 13:56:07
What is the difference between ngStorage and $window.localStorage? When is it better to use one instead that the other? I have to choose one of them for a web app. I have to save data of profile user and the token sebenalern This is normal html5 local storage: With local storage, web applications can store data locally within the user's browser. Before HTML5, application data had to be stored in cookies, included in every server request. Local storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Unlike cookies, the storage limit is far

Angular 2.0 Release: Pipes and Directives are not properties of @Component anymore

*爱你&永不变心* 提交于 2019-12-03 11:19:00
问题 I just upgraded my app which I built on RC5 to the final release, and I'm confused of the way I should be declaring Directives and Pipes now. I'm getting this error: ERROR in [default] C:\xampp\htdocs\meriem-car\public\src\app\components\administration.component.ts:12:4 Argument of type '{ moduleId: string; selector: string; directives: typeof LoginComponent[]; templateUrl: string; }' is not assignable to parameter of type 'Component'. Object literal may only specify known properties, and

Detect Click outside element in angular 4 using directives

混江龙づ霸主 提交于 2019-12-03 08:39:36
问题 I have used a custom directive to detect click outside an element in angular 2 but the same is not possible in angular 4. [plunkr] https://plnkr.co/edit/aKcZVQ?p=info When I try using the same code in angular-4 I get the following errors: 1. Argument of type '{ template: string; directives: typeof ClickOutside[]; }' is not assignable to parameter of type 'Component'. ==> @Component({ templateUrl: "", directives: [ClickOutside] }) 2. Type 'Subscription' is not assignable to type 'Observable

How to get element's width/height within directives and component?

一个人想着一个人 提交于 2019-12-03 07:01:50
问题 @Component({ selector: '.donation', template: ` <figure id="donation" move> <img src="image/qrcode.png"/> <figcaption> Buy me a cup of coffee. </figcaption> </figure> ` }) export class DonationComponent{} @Directive({ selector: '[move]' }) export class MoveDirective{} Hey,I want to get element's width/height within MoveDirective and DonationComponent,I read the document several times but still can not find a way to this answer.Do somebody know this please help me,thanks a lot! 回答1: You can

Can a directive delete itself from a parent scope

蹲街弑〆低调 提交于 2019-12-03 06:32:57
Let's say I have the following code <div ng-app="app" ng-controller="controller"> <div ng-repeat="instance in instances> <customDirective ng-model="instance"></customDirective> </div> </div> And my custom directive has an isolated scope, defined as: app.directive('customDirective', function($log) { return { restrict: 'E', templateUrl: './template.htm', scope: {_instance:"=ngModel"}, link: function($scope) { .... } }); In this directive, I have to option to delete it. My question is how can I communicate back to the array instances in the parent scope and tell it to destroy this object and in

Detect Click outside element in angular 4 using directives

那年仲夏 提交于 2019-12-03 00:09:24
I have used a custom directive to detect click outside an element in angular 2 but the same is not possible in angular 4. [plunkr] https://plnkr.co/edit/aKcZVQ?p=info When I try using the same code in angular-4 I get the following errors: 1. Argument of type '{ template: string; directives: typeof ClickOutside[]; }' is not assignable to parameter of type 'Component'. ==> @Component({ templateUrl: "", directives: [ClickOutside] }) 2. Type 'Subscription' is not assignable to type 'Observable<MouseEvent>'. in the directive inside ngOnInit() and ngOnDestroy() ngOnInit() { this.globalClick =