angular ng-repeat in reverse

I would suggest using a custom filter such as this: app.filter(‘reverse’, function() { return function(items) { return items.slice().reverse(); }; }); Which can then be used like: <div ng-repeat=”friend in friends | reverse”>{{friend.name}}</div> See it working here: Plunker Demonstration This filter can be customized to fit your needs as seen fit. I have provided other examples … Read more

ng-app vs. data-ng-app, what is the difference?

Good question. The difference is simple – there is absolutely no difference between the two except that certain HTML5 validators will throw an error on a property like ng-app, but they don’t throw an error for anything prefixed with data-, like data-ng-app. So to answer your question, use data-ng-app if you would like validating your … Read more

Processing $http response in service

Here is a Plunk that does what you want: http://plnkr.co/edit/TTlbSv?p=preview The idea is that you work with promises directly and their “then” functions to manipulate and access the asynchronously returned responses. app.factory(‘myService’, function($http) { var myService = { async: function() { // $http returns a promise, which has a then function, which also returns a … Read more

Show spinner GIF during an $http request in AngularJS?

This really depends on your specific use case, but a simple way would follow a pattern like this: .controller(‘MainCtrl’, function ( $scope, myService ) { $scope.loading = true; myService.get().then( function ( response ) { $scope.items = response.data; }, function ( response ) { // TODO: handle the error somehow }).finally(function() { // called no matter … Read more

How can I conditionally require form inputs with AngularJS?

There’s no need to write a custom directive. Angular’s documentation is good but not complete. In fact, there is a directive called ngRequired, that takes an Angular expression. <input type=”email” name=”email” ng-model=”contact.email” placeholder=”your@email.com” ng-required=’!contact.phone’ /> <input type=”text” ng-model=”contact.phone” placeholder=”(xxx) xxx-xxxx” ng-required=’!contact.email’ /> Here’s a more complete example: http://jsfiddle.net/uptnx/1/

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