How to bind boolean values in angular directives?

You can configure your own 1-way databinding behavior for booleans like this: link: function(scope, element, attrs) { attrs.$observe(‘collapsable’, function() { scope.collapsable = scope.$eval(attrs.collabsable); }); } Using $observe here means that your “watch” is only affected by the attribute changing and won’t be affected if you were to directly change the $scope.collapsable inside of your directive.

Why is ngModel.$setViewValue(…) not working from

The reason is that since you’re creating an isolated scope for your contenteditable directive, the ng-model directive on the same element gets that isolated scope as well. Which means that you have two different scopes that aren’t connected to each other, which both have a form.userContent property that changes separately. I guess you could exemplify … Read more

How to share the $scope variable of one controller with another in AngularJS?

You could use an Angular Service to share variable acrosss multiple controllers. angular.module(‘myApp’, []) .service(‘User’, function () { return {}; }) To share the data among independent controllers, Services can be used. Create a service with the data model that needs to be shared. Inject the service in the respective controllers. function ControllerA($scope, User) { … Read more

Get DOM element by scope $id

Although it’s not very sexy each dom node gets a class ng-scope so you could tech do something like this maybe: function getScope(id) { var elem; $(‘.ng-scope’).each(function(){ var s = angular.element(this).scope(), sid = s.$id; if(sid == id) { elem = this; return false; // stop looking at the rest } }); return elem; }

how to call function when angular watch cycle or digest cycle is completed

There are couple of ways to do register a callback once a digest is completed. Using $$postDigest: $scope.$$postDigest fires a callback after the current $digest cycle completed. However this runs only once after the next digest cycle. To make it run after each digest cycle run it along with $watch. This is based on the … Read more

accessing $scope from unit test file when using the vm “ControllerAs” syntax from AngularJS HotTowel

Ah, obvious now…I can access the vm variable through making a reference to the controller that’s created in the test: it(“should assign Dashboard as title”, function () { var vm = controller(“dashboard”, { $scope: scope }); expect(vm.title).toBe(“Dashboard”); });

The correct way to inject an angular controller dependency inside an angular.ui modal

You question is not very clear, but if you declare controller using the module API, then you can provide the controller to the modal service as a string myApp.controller(‘ModalInstanceCtrl’, [‘$scope’, function($scope) { $scope.greeting = ‘Hola!’; }]); controller: ‘ModalInstanceCtrl’, The same can be done for loginCtrl if you want to use that in the modal service.

Is it Possible to Update Parent Scope from Angular Directive with scope: true?

Although @user1737909 already referenced the SO question to read (What are the nuances of scope prototypal / prototypical inheritance in AngularJS?, which will explain the problem and recommended various ways to fix it), we normally try to give the answer on SO. So, the reason your fiddle doesn’t work is because when a primitive type … Read more

Behavior of assignment expression invoked by ng-click within ng-repeat

Directive ngRepeat creates a new scope for each iteration, so you need to reference your variables in parent scope. Use $parent.selected = value, as in: <p ng-repeat=”value in values” ng-click=’$parent.selected = value’>{{value}}</p> Note: Function call propagates due to prototypal inheritance. If you want to learn more: The Nuances of Scope Prototypal Inheritance.

tech