How to check if a method argument of a directive is specified in AngularJS?

Using ‘&?’ returns undefined if the attribute has not been set. ‘&’ = callback function is defined always. ‘&?’ = callback function is defined only when attribute is defined in html template. bindToController: { callback: ‘&?’ }, controller: function() { if (this.callback === undefined) { // attribute “callback” was not defined } } Note: Works … Read more

How do I fix a “type or namespace name could not be found” error in Visual Studio?

This can be the result of a .NET Framework version incompatibility between two projects. It can happen in two ways: a client profile project referencing a full framework project; or an older framework version targeting a newer framework version For example it will happen when an application is set to target the .NET 4 Client … Read more

What are practical scenarios of *ngTemplateOutlet directive?

Angular template outlets can be used to insert a common template in various sections of a view that are not generated by a loop or subject to a condition. For example, you can define a template for the logo of a company and insert it in several places in the page: <div> <ng-container *ngTemplateOutlet=”companyLogoTemplate”></ng-container> <h1>Company … Read more

Define AngularJS directive using TypeScript and $inject mechanism

Using classes and inherit from ng.IDirective is the way to go with TypeScript: class MyDirective implements ng.IDirective { restrict=”A”; require=”ngModel”; templateUrl=”myDirective.html”; replace = true; constructor(private $location: ng.ILocationService, private toaster: ToasterService) { } link = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, ctrl: any) => { console.log(this.$location); console.log(this.toaster); } static factory(): ng.IDirectiveFactory { const directive = ($location: … Read more

Angular JS resizable div directive

This question is old, but for anybody looking for a solution, I built a simple directive to handle this, for vertical and horizontal resizers. Take a look at the Plunker angular.module(‘mc.resizer’, []).directive(‘resizer’, function($document) { return function($scope, $element, $attrs) { $element.on(‘mousedown’, function(event) { event.preventDefault(); $document.on(‘mousemove’, mousemove); $document.on(‘mouseup’, mouseup); }); function mousemove(event) { if ($attrs.resizer == ‘vertical’) … Read more

AngularJS $watch window resize inside directive

You shouldn’t need a $watch. Just bind to resize event on window: DEMO ‘use strict’; var app = angular.module(‘plunker’, []); app.directive(‘myDirective’, [‘$window’, function ($window) { return { link: link, restrict: ‘E’, template: ‘<div>window size: {{width}}px</div>’ }; function link(scope, element, attrs){ scope.width = $window.innerWidth; angular.element($window).bind(‘resize’, function(){ scope.width = $window.innerWidth; // manuall $digest required as resize event … Read more

Passing array via attribute to AngularJS directive

If you’re accessing this array from your scope, i.e. loaded in a controller, you can just pass the name of the variable: Binding array to directive variable in AngularJS Directive: scope:{ title: “@”, author: “@”, content: “@”, cover: “@”, date: “@”, tags: “=” }, Template: <post title=”sample title” tags=”arrayName” … >

How to use Angular structural directive with multiple inputs

The input names need all to be prefixed with the selector of the directive, followed by the input name capitalized (i.e. permissionIfExcept). Example: @Directive({ selector: ‘[permissionIf]’ }) export class PermissionIfDirective implements AfterContentInit { private _permissionIf:string[]; @Input() set permissionIf(value: string[]) { this._permissionIf=value; console.log(‘permissionIf: ‘, value); } private _except:string; @Input() set permissionIfExcept(value: string) { this._except = value; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)