Watch multiple $scope attributes

Starting from AngularJS 1.3 there’s a new method called $watchGroup for observing a set of expressions. $scope.foo = ‘foo’; $scope.bar=”bar”; $scope.$watchGroup([‘foo’, ‘bar’], function(newValues, oldValues, scope) { // newValues array contains the current values of the watch expressions // with the indexes matching those of the watchExpression array // i.e. // newValues[0] -> $scope.foo // and … Read more

Angular ng-repeat Error “Duplicates in a repeater are not allowed.”

The solution is actually described here: http://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/ AngularJS does not allow duplicates in a ng-repeat directive. This means if you are trying to do the following, you will get an error. // This code throws the error “Duplicates in a repeater are not allowed. // Repeater: row in [1,1,1] key: number:1″ <div ng-repeat=”row in [1,1,1]”> … Read more

AngularJS : Initialize service with asynchronous data

Have you had a look at $routeProvider.when(‘/path’,{ resolve:{…}? It can make the promise approach a bit cleaner: Expose a promise in your service: app.service(‘MyService’, function($http) { var myData = null; var promise = $http.get(‘data.json’).success(function (data) { myData = data; }); return { promise:promise, setData: function (data) { myData = data; }, doStuff: function () { … Read more

Redirecting to a certain route based on condition

After some diving through some documentation and source code, I think I got it working. Perhaps this will be useful for someone else? I added the following to my module configuration: angular.module(…) .config( [‘$routeProvider’, function($routeProvider) {…}] ) .run( function($rootScope, $location) { // register listener to watch route changes $rootScope.$on( “$routeChangeStart”, function(event, next, current) { if … Read more

Complex nesting of partials and templates

UPDATE: Check out AngularUI’s new project to address this problem For subsections it’s as easy as leveraging strings in ng-include: <ul id=”subNav”> <li><a ng-click=”subPage=”section1/subpage1.htm””>Sub Page 1</a></li> <li><a ng-click=”subPage=”section1/subpage2.htm””>Sub Page 2</a></li> <li><a ng-click=”subPage=”section1/subpage3.htm””>Sub Page 3</a></li> </ul> <ng-include src=”https://stackoverflow.com/questions/12863663/subPage”></ng-include> Or you can create an object in case you have links to sub pages all over the place: … Read more

What is the difference between Polymer elements and AngularJS directives?

You’re not the first to ask this question 🙂 Let me clarify a couple of things before getting to your questions. Polymer’s webcomponents.js is a library that contains several polyfills for various W3C APIs that fall under the Web Components umbrella. These are: Custom Elements HTML Imports <template> Shadow DOM Pointer Events others The left-nav … Read more

AngularJS ngClass conditional

Your first attempt was almost right, It should work without the quotes. {test: obj.value1 == ‘someothervalue’} Here is a plnkr. The ngClass directive will work with any expression that evaluates truthy or falsey, a bit similar to Javascript expressions but with some differences, you can read about here. If your conditional is too complex, then … Read more

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