Created
June 26, 2014 16:20
-
-
Save sanusart/ddb054ad79d91ba5b068 to your computer and use it in GitHub Desktop.
AngularJS base snippets #Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Routing | |
angular.module('myAppName', []) | |
.config(function($routeProvider) { | |
$routeProvider | |
.when('/', { | |
templateUrl: 'views/home.html', | |
controller: 'homeCtrl' | |
}) | |
.when('/inner', { | |
templateUrl: 'views/inner.html', | |
controller: 'innerCtrl' | |
}) | |
.otherwise({ | |
redirectTo: '/' | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Conteroller | |
angular.module('myAppName', []) | |
.controller('controllerNameCtrl', function($scope) { | |
// Conroller stuff here | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// directive | |
angular.module('myAppName', []) | |
.directive('directiveName', function (injectables) { | |
return { | |
restrict: 'A', // A,E,M,C or even AE | |
template: '<div></div>', | |
templateUrl: 'directive.html', // If present | |
replace: false, | |
priority: 0, | |
transclude: false, | |
scope: false, | |
terminal: false, | |
require: false, | |
controller: function($scope, $element, $attrs, $transclude, otherInjectables) { | |
// Controller if used | |
}, | |
compile: function compile(tElement, tAttrs, transclude) { | |
return { | |
pre: function preLink(scope, iElement, iAttrs, controller) { | |
// pre-link function() | |
}, | |
post: function postLink(scope, iElement, iAttrs, controller) { | |
// post-link function() - executed by link() | |
} | |
}; | |
}, | |
link: function postLink(scope, iElement, iAttrs) { | |
return { | |
pre: function preLink(scope, iElement, iAttrs, controller) { | |
// pre-link function() | |
}, | |
post: function postLink(scope, iElement, iAttrs, controller) { | |
// post-link function() - executed by link() | |
} | |
}; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment