Archive

Posts Tagged ‘javascript’

AngularJS CheatSheet

ng-app (usually on html)

ng-controller (on the body or on the container)

‘use strict’;

scripts order: Jquery – Angular (in the head possibly) other scripts: 

var testApp = angular.module(‘myFirstAng’, []);
testApp.controller(‘myController’, function ($scope) {
$scope.Test = “hello world”;
});


 

use of $http:

myApp.controller(‘myController’, function ($scope, $http) {

$http({
dataType: ‘json’, headers: {
“Content-Type”: “application/json”
}, data: ”, method: ‘GET’,
url: ‘/api/Sdb’
}).success(function (data, status, headers, config) {
$scope.Result = data;
})
.error(function (data, status, headers, config) {
}); 
});


 

NG-Repeat: ng-repeat=”friend in friends”

ng-click

<select
data-ng-model=”selection.bg”
data-ng-options=”bg.Name for bg in businessGroups”
data-ng-change=”ChangeEvent()” >
<option value=””>-Select-</option>
</select>


 

ng-grid

 <div class=“gridStyle” ng-grid=“gridOptions” style=“width: 90%; height: 90%”></div>

 

 $scope.gridOptions = {
                data: ‘users’, columnDefs: [
                    { field: ‘FullName’, displayName: ‘FullName’, resizable:true, width:200 },
                    { field: ‘UserName’, displayName: ‘UserName’, resizable: true },
                    {
                        field: ‘LastLogin’, displayName: ‘LastLogin’,
                        cellFilter: “date:’dd/MM/yyyy HH:mm'”
                    },
                    { field: ‘AssignedRoles’, displayName: ‘AssignedRoles’, resizable: true, cellFilter: ‘stringArrayFilter’ }]
            };
 
getUsersService.getUsers(data).then(
                            function (dataReturned) {
                                $scope.users = dataReturned;
                            });
 

Jasmine testing:
describe("myApp", function() {
 
    beforeEach(module('myApp'));
 
    describe("SimpleController", function() {
 
        var scope;
        beforeEach(inject(function($rootScope, $controller) {
            scope = $rootScope.$new();
            $controller("SimpleController", {
                $scope: scope
            });
        }));
 
        it("should double the numbers", function() {
            scope.doubleIt();
            expect(scope.x).toBe(6);
        });
    });
});
 
Categories: DEV, Test Tags: ,

GeoLoaction in Javascript

I found this free service for GeoLocation in Javascript…

<script language='JavaScript' src='http://j.maxmind.com/app/geoip.js'></script>
<script language='JavaScript'>document.write(geoip_country_code());</script>
<script language='JavaScript'>
if(geoip_country_code()=="IT")
{
//Redirect ALL users from ITALY on google.com
location.replace("http://www.google.com");
}
</script>

the code is extremely easy to use, anyway I am looking forward for the proper GeoLocation API shipped with HTML5

Categories: DEV Tags: ,

JTemplates vs JQuery Template

this is one of the Jquery and UI development cool stuffs that I used in a past project…

http://plugins.jquery.com/project/jTemplates

basically you can define an html template and apply your Jquery logic so that you can separate easily the html from the JQuery logic.

latest Jquery versions officially support an other plugin http://api.jquery.com/jQuery.template/
Categories: DEV Tags: ,

Json Converter

have you never need to serialize an object as Json on the page Load for further use on Javascript?!

well, I found this project very interesting…http://json.codeplex.com/Wikipage

on my projects this serializer worked perfectly, take a look at that!

Categories: DEV Tags: , ,