Angular JS

Always use Restangular instead of $resource or $http

Advantages of Restangular over $http It uses promises. Instead of doing the “magic” filling of objects like $resource, it uses promises. You can use this in $routeProvider.resolve. As Restangular returns promises, you can return any of the methods in the $routeProvider.resolve and you’ll get the real object injected into your controller if you want. It… Continue reading Always use Restangular instead of $resource or $http

Angular JS

Using $cookieStore in Angular JS

app.controller(‘MainCtrl’, [‘$cookieStore’, function($cookieStore) { $cookieStore.put(‘icar’,car); // to store values on cookies var car_detail = $cookieStore.get(‘icar’); // to retrieve values on cookies $cookieStore.remove(‘icar’); // to remove cookies }

Angular JS

Angular JS Dynamic searching for a collection of objects, with min & max range (i.e., persons with age from 18 to 60)

View:- <div ng-repeat=”car in cars | filter: byRange(fieldname, min_value, max_value” > ……. …… </div> Controller:- $scope.byRange = function (fieldName, minValue, maxValue) { if (minValue === undefined) minValue = Number.MIN_VALUE; if (maxValue === undefined) maxValue = Number.MAX_VALUE; return function predicateFunc(item) { return minValue <= item[fieldName] && item[fieldName] <= maxValue; }; }; That’s it just pass in… Continue reading Angular JS Dynamic searching for a collection of objects, with min & max range (i.e., persons with age from 18 to 60)

Angular JS

Angular JS – Mandatory and Email validations

<!DOCTYPE html> <html> <head> <script src= “http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js”></script&gt; </head> <body> <h2>Validation Example</h2> <form ng-app=”” ng-controller=”validateCtrl” name=”myForm” novalidate> <p>Username:<br> <input type=”text” name=”user” ng-model=”user” required> <span style=”color:red” ng-show=”myForm.user.$dirty && myForm.user.$invalid”> <span ng-show=”myForm.user.$error.required”>Username is required.</span> </span> </p> <p>Email:<br> <input type=”email” name=”email” ng-model=”email” required> <span style=”color:red” ng-show=”myForm.email.$dirty && myForm.email.$invalid”> <span ng-show=”myForm.email.$error.required”>Email is required.</span> <span ng-show=”myForm.email.$error.email”>Invalid email address.</span> </span> </p> <p>… Continue reading Angular JS – Mandatory and Email validations

Angular JS

Angular JS – Bootstrap Popup, Search, Sort

note.html <html ng-app=”myNoteApp”> <head> <script src=”http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js”></script&gt; <script src=”ui-bootstrap-tpls-0.12.0.min.js”></script> <link rel=”stylesheet” href=”bootstrap.css”/> </head> <body> <div ng-controller=”myNoteCtrl”> <button ng-click=”openModal();”>Search</button> </div> <script src=”myNoteApp.js”></script> <script src=”myNoteCtrl.js”></script> </body> </html> myNoteApp.js var app = angular.module(“myNoteApp”, [‘ui.bootstrap’]); var ModalInstanceCtrl = function ($scope, $modalInstance, $parse) { $scope.items = [{country: “India”, name: “Babu”}, {country: “US”, name: “Arun”},{country: “Swiss”, name: “Sri”}]; $scope.selected = { item:… Continue reading Angular JS – Bootstrap Popup, Search, Sort

Angular JS · Rails4 · Ruby On Rails

Angular JS implementation with Rails 4

Step 1 :¬†Create rails app using rails new employee_detailsStep 2 : Remove turbolinks gem from gemfile and add ‘pg’ gem for postgres. Set the rails version to 4.1.2 (Turbolinks may not work with angular js)Step 3 : Run bundle installStep 4 : Change database.yml to use postgresdevelopment: adapter: postgresql encoding: unicode database: employee_details username: postgres… Continue reading Angular JS implementation with Rails 4