Angular: calling controller function inside a directive link function using &

Are you passing the arguments inside {}s? E.g., inside the directive’s link function, you’ll want to call the method like so: scope.someCtrlFn({arg1: someValue}); <div my-directive callback-fn=”ctrlFn(arg1)”></div> app.directive(‘myDirective’, function() { return { scope: { someCtrlFn: ‘&callbackFn’ }, link: function(scope, element, attrs) { scope.someCtrlFn({arg1: 22}); }, } }); function MyCtrl($scope) { $scope.ctrlFn = function(test) { console.log(test); } … Read more

Using a directive inside an ng-repeat, and a mysterious power of scope ‘@’

In drinkLonghand, you use the code scope.flavor = attrs.flavor; During the linking phase, interpolated attributes haven’t yet been evaluated, so their values are undefined. (They work outside of the ng-repeat because in those instances you aren’t using string interpolation; you’re just passing in a regular ordinary string, e.g. “strawberry”.) This is mentioned in the Directives … Read more

Set focus on first invalid input in AngularJs form

Ok, so the answer was simpler than I thought. All I needed was a directive to put on the form itself, with an event handler looking for the submit event. This can then traverse the DOM looking for the first element that has the .ng-invalid class on it. Example using jQLite: myApp.directive(‘accessibleForm’, function () { … Read more

Angular directive for a fallback image

No but you can create one. http://jsfiddle.net/FdKKf/ HTML: <img fallback-src=”http://google.com/favicon.ico” ng-src=”{{image}}”/> JS: myApp.directive(‘fallbackSrc’, function () { var fallbackSrc = { link: function postLink(scope, iElement, iAttrs) { iElement.bind(‘error’, function() { angular.element(this).attr(“src”, iAttrs.fallbackSrc); }); } } return fallbackSrc; });

Find child element in AngularJS directive

jQlite (angular’s “jQuery” port) doesn’t support lookup by classes. One solution would be to include jQuery in your app. Another is using QuerySelector or QuerySelectorAll: link: function(scope, element, attrs) { console.log(element[0].querySelector(‘.list-scrollable’)) } We use the first item in the element array, which is the HTML element. element.eq(0) would yield the same. FIDDLE

AngularJS Directive Passing String

In your directive, you’re using the bi-directional binding of attributes from the global scope to the directive local scope. In this mode, the attribute value in the html is evaluated as an expression and thus your directive tries to bind its local scope.error to the result of evaluating true as an expression. When you test … Read more

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