Skip to content

Instantly share code, notes, and snippets.

View cpoDesign's full-sized avatar

Pavel cpoDesign

View GitHub Profile
@cpoDesign
cpoDesign / gist:c934d0a8bc04fd53f580
Last active August 29, 2015 14:01
String comparison using different implementation and its results
using System;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
const string PostcodeSubstitute = "PJ15 8JJ";
const string MatchingPostcode = "PJ15 8QJ";
@cpoDesign
cpoDesign / gist:37b602ec02b872c6368f
Last active August 29, 2015 14:02
Basic unit testing with angular - variable in controller
// for every module you include here, you need to add required resource files into your test file
var app = angular.module('app', ['ngSanitize', 'ngResource', 'ngRoute']);
// definition of controller
'use strict';
app.controller('AdminCtr',
function AdminCtr() {
this.helpAndSupportText = 'Hello';
});
@cpoDesign
cpoDesign / gist:e37c78a8e5f4da71b45b
Created June 11, 2014 09:36
Example of creating directive that adds html to start and end of template
// use example: <my-button>
testApp.directive('myButton', function(){
return {
link: function (scope, element, attrs) {
var markup = "<button>Hello</button>";
element.prepend(markup); // adds html before any child
element.append(markup); // adds html after last child
}
}
@cpoDesign
cpoDesign / gist:0223dc05141aacc27b88
Last active August 29, 2015 14:02
Example of creating directive that adds html to start and end of template.
// used in: http://blog.cpodesign.com/blog/angular-directives-in-examples/
// use example: <my-button>
testApp.directive('myButton', function(){
return {
link: function (scope, element, attrs) {
var markup = "<button>Hello</button>";
element.prepend(markup); // adds html before any child
element.append(markup); // adds html after last child
}
@cpoDesign
cpoDesign / gist:e9267a424a623ba34e91
Created June 12, 2014 08:59
Implementing select dropdown with default select option
app.controller('myController', function($scope){
$scope.teams = [
{id:1, name:'team 1'},
{id:2, name:'team 2'},
{id:3, name:'team 3'}];
// if I want to preselect item I can do following
// $scope.myTeam = 1;
});
@cpoDesign
cpoDesign / app.js
Last active August 29, 2015 14:02
Implementing breadcrumbs into site with AngularJS v1.2.16. Implementation uses breadcrumb module by Ian Kennington Walter (http://ianvonwalter.com)
var app = angular.module('app', ['ngRoute','ng-breadcrumbs']);
app.config(function($routeProvider) {
$routeProvider.when('/',
{
templateUrl: 'templates/list.html',
controller: 'listCtr',
label:'Administration'
})
.when('/detail/',
@cpoDesign
cpoDesign / example1.js
Last active August 29, 2015 14:02
using $resource in examples
// service with parameters
// How do I not send url template parameters with request body in angular?
// Source: http://stackoverflow.com/questions/19529483/how-do-i-not-send-url-template-parameters-with-request-body-in-angular
resource = $resource(
'http://foo.com/service/:type/:id',
{},
{save: {
method:'PUT',
transformRequest:function(data) {
delete data.type;
@cpoDesign
cpoDesign / index.html
Created June 16, 2014 12:27
Generic implementation for loader. It will target root scope while any promise is in process
<p>
Implementation of loader in $rootScope
</p>
<div style="float:right;padding-top:1em;" data-ng-show="loading">
<img src="~/images/ajax-loader-inline.gif" /> Loading, please wait ...
</div>
@cpoDesign
cpoDesign / notificationBar.js
Last active August 29, 2015 14:02
Original implementation of directive message, contains only error message
.directive("notificationBar", function () {
return {
transclude: false,
require: '^ngModel',
templateUrl: 'notificationBar/template.html',
scope: {
displayMessage: '@'
},
controller: function ($scope){
$scope.showMessage = function() {
@cpoDesign
cpoDesign / app.js
Created June 18, 2014 14:52
New version of notification directive to allow add errorMessage, successMessage, warnMessage
var app = angular.module('app', []);
app.controller('priorityCtr',
function priorityCtr($rootScope, $scope){
$scope.showError = function(){
$rootScope.errorMessage='test error message';
$rootScope.successMessage='';
$rootScope.warnMessage='';
};