How to expose a public API from a directive that is a reusable component?

Does this work for you? angular.directive(‘extLabel’, function() { return { restrict: ‘E’, scope: { api: ‘=’ }, link: function(scope, iElement, iAttrs) { scope.api = { doSomething: function() { }, doMore: function() { } }; } }; }); From containing parent <ext:label api=”myCoolApi”></ext:label> And in controller $scope.myCoolApi.doSomething(); $scope.myCoolApi.doMore();

angular.js $destroy event – should I manually unbind?

According to Angular documentation on $scope: ‘$destroy()’ must be called on a scope when it is desired for the scope and its child scopes to be permanently detached from the parent and thus stop participating in model change detection and listener notification by invoking. Also Removal also implies that the current scope is eligible for … Read more

Having a hard time debugging error – Token ‘{‘ invalid key at column 2

I notice that this error also happens when binding data to an attribute on a custom directive. Where $scope.myData.value = “Hello!”; This causes the error: <my-custom-directive my-attr=”{{myData.value}}”></my-custom-directive> But this works fine: <my-custom-directive my-attr=”myData.value”></my-custom-directive>

AngularJS – Format Text Return From JSON To Title Case

A filter is an ideal solution for this purpose <div ng-repeat=”name in FootballClubs”> {{ name.CompanyName | titleCase }} </div> So the filter itself would be angular.module(‘myFootballModule’, []) .filter(‘titleCase’, function() { return function(input) { input = input || ”; return input.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); }; })

How to trigger a method when Angular is done adding scope updates to the DOM?

The $evalAsync queue is used to schedule work which needs to occur outside of current stack frame, but before the browser’s view render. — http://docs.angularjs.org/guide/concepts#runtime Okay, so what’s a “stack frame”? A Github comment reveals more: if you enqueue from a controller then it will be before, but if you enqueue from directive then it … Read more

Get controller name from $scope

I’m not sure this is a good solution, but I was able to inject $scope.controllerName using this technique: app.config([‘$provide’, function ($provide) { $provide.decorator(‘$controller’, [ ‘$delegate’, function ($delegate) { return function(constructor, locals) { if (typeof constructor == “string”) { locals.$scope.controllerName = constructor; } return $delegate.apply(this, [].slice.call(arguments)); } }]); }]); Then app.controller(‘SampleCtrl’, [‘$scope’, ‘$log’, function ($scope, $log) … Read more

Running $apply on $rootScope vs any other scope

Running $apply on any scope always results in a $rootscope.$digest. The only case where it might make a difference is when you provide an expression as an argument to $apply. The expression will be evaluated in the current scope (vs. $rootScope), but afterwards $rootscope.$digest is always called. The source code is quite clear: rootScope.js Bottom … Read more

AngularJS : ng-repeat filter when value is greater than

Create a predicate function on the relevant scope: $scope.greaterThan = function(prop, val){ return function(item){ return item[prop] > val; } } As a first argument, it takes a property name on the object. The second argument is an integer value. Use it in your view like this: <tr ng-repeat-start=”list in Data.Items | filter: greaterThan(‘NumberOfStamps’, 0)”> Demo

Custom child directive accessing scope of parent

The city directive $parent is a transcluded scope of state directive. The transcluded scope of the state directive is inherit for $parent of state directive which is controller thus that is why $parent.MyName = India. The $parent of transcluded scope is the state directive isolated scope ( scope = {} ) that is why $parent.$parent.MyName … Read more

ng-click doesn’t work within the template of a directive

You’ve got a scope issue. Since you used isolated scope in your directive with scope: { value: ‘=’ }, it no longer has access to your controller’s scope that has editQuestion. You need to pass editQuestion along to your directive’s scope so it knows how to call it. This is typically pretty easy, but because … Read more

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