Should angular $watch be removed when scope destroyed?

No, you don’t need to remove $$watchers, since they will effectively get removed once the scope is destroyed. From Angular’s source code (v1.2.21), Scope‘s $destroy method: $destroy: function() { … if (parent.$$childHead == this) parent.$$childHead = this.$$nextSibling; if (parent.$$childTail == this) parent.$$childTail = this.$$prevSibling; if (this.$$prevSibling) this.$$prevSibling.$$nextSibling = this.$$nextSibling; if (this.$$nextSibling) this.$$nextSibling.$$prevSibling = this.$$prevSibling; … … Read more

Confused about Angularjs transcluded and isolate scopes & bindings

Your fiddles create three scopes: a scope associated with controller Ctrl, because of ng-controller a directive transcluded scope, because of transclude: true a directive isolate scope, because of scope: { … } In fiddle1, before we type anything into the text box we have the following: Scope 003 is the scope associated with the controller. … Read more

AngularJS ngRepeat element removal

You could create a generic remove method that would take in the array and the item to remove. <div ng-app=”” ng-controller=”MyController”> <div ng-repeat=”email in emails”>{{ email }} <a ng-click=”remove(emails, $index)”>Remove</a> </div> <div ng-repeat=”phone in phones”>{{ phone }} <a ng-click=”remove(phones, $index)”>Remove</a> </div> </div> $scope.remove = function(array, index){ array.splice(index, 1); }

$watch not being triggered on array change

Try $watch(‘tasks.length’, …) or $watch(‘tasks’, function(…) { … }, true). By default, $watch does not check for object equality, but just for reference. So, $watch(‘tasks’, …) will always simply return the same array reference, which isn’t changing. Update: Angular v1.1.4 adds a $watchCollection() method to handle this case: Shallow watches the properties of an object … Read more

AngularJS event on window innerWidth size change

We could do it with jQuery: $(window).resize(function(){ alert(window.innerWidth); $scope.$apply(function(){ //do something to update current scope based on the new innerWidth and let angular update the view. }); }); Be aware that when you bind an event handler inside scopes that could be recreated (like ng-repeat scopes, directive scopes,..), you should unbind your event handler when … Read more

AngularJS directive dynamic templates

You can set the template property of your directive definition object to a function that will return your dynamic template: restrict: “E”, replace: true, template: function(tElement, tAttrs) { return getTemplate(tAttrs.content); } Notice that you don’t have access to scope at this point, but you can access the attributes through tAttrs. Now your template is being … Read more

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