Skip to content

Instantly share code, notes, and snippets.

View icfantv's full-sized avatar

Adam Gordon icfantv

View GitHub Profile
<div class="form-group"
data-ng-class="{'has-error': options.validation.errorExistsAndShouldBeVisible}">
<label for="{{ ::id }}" class="control-label">
{{ ::to.label }}
<span data-ng-if="::to.required" class="text-red">*</span>
</label>
<formly-transclude></formly-transclude>
<div class="my-messages" data-my-messages="options"></div>
</div>
@icfantv
icfantv / AuthorizationService.js
Created June 2, 2015 03:33
Authorization Service
function AuthorizationService($injector, $cookieStore, $window, StringUtils, AuthConstants) {
var token = $cookieStore.get(AuthConstants.cookie);
function getUser() {
return token.user;
}
function hasPermission(resourceName, permissionName) {
return _.some(getUser().roles, function(role) {
define(['angular-animate',
'angular-messages'], function() {
'use strict';
var app = angular.module('my-module', [
'ngRoute',
'ngAnimate',
'ngMessages']);
app.config(['$logProvider', '$routeProvider', 'DashboardConstants', InitializeRouteProvider]);
app.config(['$httpProvider', InitializeHttpProvider]);
@icfantv
icfantv / app.js
Last active September 10, 2015 17:10
Promises Example
var app = angular.module('app', []);
app.service('MyHttpService', ['$http', MyHttpService]);
function MyHttpService($http) {
this.doHttpCall = function() {
return $http.get('/foo.json');
};
}
app.service('MyService', ['$q', MyService]);
@icfantv
icfantv / controller.js
Created December 11, 2015 00:10
Multi Checkbox Example
module.controller('FormlyMultiCheckboxController', ['$scope', FormlyMultiCheckboxController]);
function FormlyMultiCheckboxController($scope) {
var to = $scope.to;
var opts = $scope.options;
$scope.multiCheckbox = {
checked: [],
change: setModel,
selectAll: false,
toggleSelectAll: toggleSelectAll
@icfantv
icfantv / AuthService.js
Last active January 6, 2016 20:37
AuthService with promise and cache
angular.service('AuthService', function($q, $http) {
var authStuff, promise;
this.login = function(credentials) {
if (!authStuff) {
promise = $http.post(...).then(function(response) { authStuff = response.data; });
}
return $q(function(resolve, reject) {
@icfantv
icfantv / controllers.js
Last active January 11, 2016 17:50
Modal Example
function ModalController($scope, $uibModalInstance) {
$scope.data = {};
$scope.data.form = {};
$scope.close = function() {
$uibModalInstace.close($scope.data.form);
}
$scope.cancel = function() {
@icfantv
icfantv / function.js
Last active February 10, 2016 19:40
Username Validation
vm.username = function($viewValue, $modelValue, scope) {
// check if username matches regex before validating
var value = $modelValue || $viewValue, deferred = $q.defer();
if (UserConfig.ID_REGEX.test(value)) {
scope.options.templateOptions.loading = true;
UserService.username(value).then(function() {
deferred.reject(false);
@icfantv
icfantv / MyDirective.js
Created February 4, 2016 02:17
ES6 modules, Angular Directives, and you
export function MyDirective() {
return {
restrict: 'E',
controller: 'MyDirectiveController',
controllerAs: 'snoopy',
scope: {
stuff: '=yoGimmeSomeStuff'
},
templateUrl: 'components/snoopy/views/gimme-some-stuff-template.html'
};
@icfantv
icfantv / SampleRouteConfiguration.js
Created February 12, 2016 20:23
Sample Route Provider
export function SampleRouteConfiguration($routeProvider) {
$routeProvider.when('/customer', {
controller: 'CustomerListController',
controllerAs: 'customers',
templateUrl: 'path/to/customers.html',
resolve: {
consumers: ['CustomerService', CustomerService => CustomerService.getAll()]
}
}).when('/customer/:id', {
controller: 'CustomerController',