Skip to content

Instantly share code, notes, and snippets.

@martianyi
martianyi / fileModel.js
Last active March 21, 2017 02:16
angularjs directive to upload file
var fileModel = angular.module('directives.fileModel', []);
fileModel.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function(){
@martianyi
martianyi / classRoute.js
Last active March 21, 2017 02:24
angularjs classRoute directive, usage <body class-route=" ">
var classRoute = angular.module('directives.classRoute',[]);
classRoute.directive('classRoute', function($rootScope, $route) {
return function(scope, elem, attr) {
var previous = '';
$rootScope.$on('$routeChangeSuccess', function(event, currentRoute) {
var route = currentRoute.$$route;
if(route) {
@martianyi
martianyi / Gruntfile.js
Last active March 21, 2017 02:18
Gruntfile.js
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
grunt.initConfig({