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

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

Combating AngularJS executing controller twice

The app router specified navigation to MyController like so: $routeProvider.when(“https://stackoverflow.com/”, { templateUrl: ‘pages/home.html’, controller: MyController }); But I also had this in home.html: <div data-ng-controller=”MyController”> This digested the controller twice. Removing the data-ng-controller attribute from the HTML resolved the issue. Alternatively, the controller: property could have been removed from the routing directive. This problem also … Read more

Adding multiple class using ng-class

To apply different classes when different expressions evaluate to true: <div ng-class=”{class1 : expression1, class2 : expression2}”> Hello World! </div> To apply multiple classes when an expression holds true: <!– notice expression1 used twice –> <div ng-class=”{class1 : expression1, class2 : expression1}”> Hello World! </div> or quite simply: <div ng-class=”{‘class1 class2’ : expression1}”> Hello World! … Read more

Confused about Service vs Factory

All angular services are singletons: Docs (see Services as singletons): https://docs.angularjs.org/guide/services Lastly, it is important to realize that all Angular services are application singletons. This means that there is only one instance of a given service per injector. Basically the difference between the service and factory is as follows: app.service(‘myService’, function() { // service is … Read more

How to use a filter in a controller?

Inject $filter to your controller function myCtrl($scope, $filter) { } Then wherever you want to use that filter, just use it like this: $filter(‘filtername’); If you want to pass arguments to that filter, do it using separate parentheses: function myCtrl($scope, $filter) { $filter(‘filtername’)(arg1,arg2); } Where arg1 is the array you want to filter on and … Read more

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