Angularjs autocomplete from $http

I made an autocomplete directive and uploaded it to GitHub. It should also be able to handle data from an HTTP-Request. Here’s the demo: http://justgoscha.github.io/allmighty-autocomplete/ And here the documentation and repository: https://github.com/JustGoscha/allmighty-autocomplete So basically you have to return a promise when you want to get data from an HTTP request, that gets resolved when the … Read more

AngularJS : What is the best way to bind to a global event in a directive

I have chosen another method, to effectively localise global events, like window resizing. It converts Javascript events to Angular scope events, via another directive. app.directive(‘resize’, function($window) { return { link: function(scope) { function onResize(e) { // Namespacing events with name of directive + event to avoid collisions scope.$broadcast(‘resize::resize’); } function cleanUp() { angular.element($window).off(‘resize’, onResize); } … Read more

Angularjs – Pass argument to directive

You can pass arguments to your custom directive as you do with the builtin Angular-directives – by specifying an attribute on the directive-element: angular.element(document.getElementById(‘wrapper’)) .append(‘<directive-name title=”title2″></directive-name>’); What you need to do is define the scope (including the argument(s)/parameter(s)) in the factory function of your directive. In below example the directive takes a title-parameter. You can … Read more

How would you do the equivalent of preprocessor directives in Python?

There’s __debug__, which is a special value that the compiler does preprocess. if __debug__: print “If this prints, you’re not running python -O.” else: print “If this prints, you are running python -O!” __debug__ will be replaced with a constant 0 or 1 by the compiler, and the optimizer will remove any if 0: lines … Read more

How do I pass multiple attributes into an Angular.js attribute directive?

The directive can access any attribute that is defined on the same element, even if the directive itself is not the element. Template: <div example-directive example-number=”99″ example-function=”exampleCallback()”></div> Directive: app.directive(‘exampleDirective ‘, function () { return { restrict: ‘A’, // ‘A’ is the default, so you could remove this line scope: { callback : ‘&exampleFunction’, }, link: … Read more

Angular2 Can’t bind to DIRECTIVE since it isn’t a known property of element

When wrapping a property in brackets [] you’re trying to bind to it. So you have to declare it as an @Input. import { Directive, Input } from ‘@angular/core’; @Directive({ selector: ‘[appContenteditableModel]’ }) export class ContenteditableModelDirective { @Input() appContenteditableModel: string; constructor() { } } The important part is, that the member (appContenteditableModel) needs to be … Read more

Update Angular model after setting input value with jQuery

ngModel listens for “input” event, so to “fix” your code you’d need to trigger that event after setting the value: $(‘button’).click(function(){ var input = $(‘input’); input.val(‘xxx’); input.trigger(‘input’); // Use for Chrome/Firefox/Edge input.trigger(‘change’); // Use for Chrome/Firefox/Edge + IE11 }); For the explanation of this particular behaviour check out this answer that I gave a while … Read more

Calling a function when ng-repeat has finished

var module = angular.module(‘testApp’, []) .directive(‘onFinishRender’, function ($timeout) { return { restrict: ‘A’, link: function (scope, element, attr) { if (scope.$last === true) { $timeout(function () { scope.$emit(attr.onFinishRender); }); } } } }); Notice that I didn’t use .ready() but rather wrapped it in a $timeout. $timeout makes sure it’s executed when the ng-repeated elements … Read more

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